質問編集履歴
3
f
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
#解決しました
|
9
9
|
自己解決ではないので、解決した方法をこちらで
|
10
10
|
|
11
|
-
初めはCreateTweetsに
|
11
|
+
初めはCreateTweetsにpost_idを記述していた
|
12
12
|
```
|
13
13
|
class CreateTweets < ActiveRecord::Migration[5.2]
|
14
14
|
def change
|
15
15
|
create_table :tweets do |t|
|
16
16
|
省略
|
17
|
-
t.references :
|
17
|
+
t.references :post, foreign_key: { to_table: :categories }, null: false
|
18
18
|
t.references :school_b, foreign_key: { to_table: :categories }, null: false
|
19
19
|
t.references :tournament, foreign_key: { to_table: :categories }, null: false
|
20
20
|
end
|
@@ -26,7 +26,7 @@
|
|
26
26
|
```
|
27
27
|
class AddReferencesTotweets < ActiveRecord::Migration[5.2]
|
28
28
|
def change
|
29
|
-
add_references :
|
29
|
+
add_references :post, foreign_key: { to_table: :categories }, null: false
|
30
30
|
end
|
31
31
|
end
|
32
32
|
```
|
2
f
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
どういう原因が考えられますでしょうか?
|
7
7
|
|
8
8
|
#解決しました
|
9
|
-
自己解決ではないので、解決した方法
|
9
|
+
自己解決ではないので、解決した方法をこちらで
|
10
10
|
|
11
11
|
初めはCreateTweetsにschool_aを記述していた
|
12
12
|
```
|
1
d
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,4 +3,33 @@
|
|
3
3
|
ActiveRecord::StatementInvalid: Mysql2::Error: Duplicate column name 'post_id': ALTER TABLE `tweets` ADD `post_id` bigint NOT NULL
|
4
4
|
```
|
5
5
|
心当たりは、masterにマージした時に、schemaファイルにコンフリクトが起きたので、少しいじったことです
|
6
|
-
どういう原因が考えられますでしょうか?
|
6
|
+
どういう原因が考えられますでしょうか?
|
7
|
+
|
8
|
+
#解決しました
|
9
|
+
自己解決ではないので、解決した方法
|
10
|
+
|
11
|
+
初めはCreateTweetsにschool_aを記述していた
|
12
|
+
```
|
13
|
+
class CreateTweets < ActiveRecord::Migration[5.2]
|
14
|
+
def change
|
15
|
+
create_table :tweets do |t|
|
16
|
+
省略
|
17
|
+
t.references :school_a, foreign_key: { to_table: :categories }, null: false
|
18
|
+
t.references :school_b, foreign_key: { to_table: :categories }, null: false
|
19
|
+
t.references :tournament, foreign_key: { to_table: :categories }, null: false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
やっぱりこっちの方法にしようと思い、CreateTweetsの記述を消してAddReferencesTotweetsで追加していた
|
26
|
+
```
|
27
|
+
class AddReferencesTotweets < ActiveRecord::Migration[5.2]
|
28
|
+
def change
|
29
|
+
add_references :school_a, foreign_key: { to_table: :categories }, null: false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
これによってエラー
|
35
|
+
AddReferencesTotweetsを削除して元の状態に戻した(CreateTweetsに記述した)
|