回答編集履歴
1
回答を追記
test
CHANGED
@@ -61,3 +61,41 @@
|
|
61
61
|
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
|
62
62
|
|
63
63
|
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# 追記
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
> Cannot add foreign key constraint
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
参照するカラム(`reservable_room.room_id`)と参照されるカラム(`meeting_room.room_id`)のデータ型が異なっているためです。
|
76
|
+
|
77
|
+
[https://dev.mysql.com/doc/refman/5.6/ja/create-table-foreign-keys.html](https://dev.mysql.com/doc/refman/5.6/ja/create-table-foreign-keys.html)
|
78
|
+
|
79
|
+
> 外部キー内の対応するカラムと、参照されるキーは同様のデータ型を持っている必要があります。整数型のサイズと符号が同じである必要があります。
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
`meeting_room.room_id`カラムのデータ型を INT4 に変更するか、`reservable_room.room_id`カラムのデータ型を BIGINT UNSIGNED に変更してください。
|
84
|
+
|
85
|
+
[https://dev.mysql.com/doc/refman/5.6/ja/numeric-type-overview.html](https://dev.mysql.com/doc/refman/5.6/ja/numeric-type-overview.html)
|
86
|
+
|
87
|
+
> SERIAL は BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE のエイリアスです。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
---
|
92
|
+
|
93
|
+
ちなみに
|
94
|
+
|
95
|
+
> なぜ”Cannot add foreign key constraint”になるのかが不明です。
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
とのことですが、たいていの場合、エラーメッセージで検索すればすぐに原因と解決策を見つけられます。
|
100
|
+
|
101
|
+
[https://www.google.com/search?q=Cannot%20add%20foreign%20key%20constraint](https://www.google.com/search?q=Cannot%20add%20foreign%20key%20constraint)
|