質問編集履歴

2

修正

2020/07/21 09:10

投稿

avicii
avicii

スコア49

test CHANGED
File without changes
test CHANGED
@@ -14,9 +14,11 @@
14
14
 
15
15
 
16
16
 
17
+ 1回目にrake db:migrateをした時のエラー
18
+
17
19
  ```terminal
18
20
 
19
- ishiwatshinoAir:wa hiroshi$ rake db:migrate
21
+ $ rake db:migrate
20
22
 
21
23
  == 20200721090023 CreateRelationships: migrating ==============================
22
24
 
@@ -66,6 +68,60 @@
66
68
 
67
69
 
68
70
 
71
+ terminalでrails sをした時に、'bin/rake db:migrate RAILS_ENV=development'が表示され、打ち込むとこのエラーが表示されました。
72
+
73
+ ```terminal
74
+
75
+ $ bin/rake db:migrate RAILS_ENV=development
76
+
77
+ Running via Spring preloader in process 61687
78
+
79
+ == 20200721090023 CreateRelationships: migrating ==============================
80
+
81
+ -- create_table(:relationships)
82
+
83
+ rake aborted!
84
+
85
+ StandardError: An error has occurred, all later migrations canceled:
86
+
87
+
88
+
89
+ Mysql2::Error: Table 'relationships' already exists: CREATE TABLE `relationships` (`id` int(11) auto_increment PRIMARY KEY, `user_id` int(11), `follow_id` int(11), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
90
+
91
+ /Users/hiroshi/wa/db/migrate/20200721090023_create_relationships.rb:3:in `change'
92
+
93
+ -e:1:in `<main>'
94
+
95
+
96
+
97
+ Caused by:
98
+
99
+ ActiveRecord::StatementInvalid: Mysql2::Error: Table 'relationships' already exists: CREATE TABLE `relationships` (`id` int(11) auto_increment PRIMARY KEY, `user_id` int(11), `follow_id` int(11), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
100
+
101
+ /Users/hiroshi/wa/db/migrate/20200721090023_create_relationships.rb:3:in `change'
102
+
103
+ -e:1:in `<main>'
104
+
105
+
106
+
107
+ Caused by:
108
+
109
+ Mysql2::Error: Table 'relationships' already exists
110
+
111
+ /Users/hiroshi/wa/db/migrate/20200721090023_create_relationships.rb:3:in `change'
112
+
113
+ -e:1:in `<main>'
114
+
115
+ Tasks: TOP => db:migrate
116
+
117
+ (See full trace by running task with --trace)
118
+
119
+
120
+
121
+ ```
122
+
123
+
124
+
69
125
  ```db
70
126
 
71
127
  class CreateRelationships < ActiveRecord::Migration

1

修正

2020/07/21 09:10

投稿

avicii
avicii

スコア49

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,55 @@
14
14
 
15
15
 
16
16
 
17
+ ```terminal
18
+
19
+ ishiwatshinoAir:wa hiroshi$ rake db:migrate
20
+
21
+ == 20200721090023 CreateRelationships: migrating ==============================
22
+
23
+ -- create_table(:relationships)
24
+
25
+ rake aborted!
26
+
27
+ StandardError: An error has occurred, all later migrations canceled:
28
+
29
+
30
+
31
+ Mysql2::Error: Cannot add foreign key constraint: ALTER TABLE `relationships` ADD CONSTRAINT `fk_rails_be1f05b3d7`
32
+
33
+ FOREIGN KEY (`follow_id`)
34
+
35
+ REFERENCES `follows` (`id`)
36
+
37
+ /Users/hiroshi/wa/db/migrate/20200721090023_create_relationships.rb:3:in `change'
38
+
39
+
40
+
41
+ Caused by:
42
+
43
+ ActiveRecord::StatementInvalid: Mysql2::Error: Cannot add foreign key constraint: ALTER TABLE `relationships` ADD CONSTRAINT `fk_rails_be1f05b3d7`
44
+
45
+ FOREIGN KEY (`follow_id`)
46
+
47
+ REFERENCES `follows` (`id`)
48
+
49
+ /Users/hiroshi/wa/db/migrate/20200721090023_create_relationships.rb:3:in `change'
50
+
51
+
52
+
53
+ Caused by:
54
+
17
- ・エラー状態: ![イメージ説明](89d851c1820ade8f9472fa57b552dcd6.png)
55
+ Mysql2::Error: Cannot add foreign key constraint
56
+
57
+ /Users/hiroshi/wa/db/migrate/20200721090023_create_relationships.rb:3:in `change'
58
+
59
+ Tasks: TOP => db:migrate
60
+
61
+ (See full trace by running task with --trace)
62
+
63
+
64
+
65
+ ```
18
66
 
19
67
 
20
68