在我的MySQL數據庫我有兩個表的審查和產品MySQL錯誤無法添加當我添加外鍵約束外鍵
mysql> desc review;
+---------------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| review | varchar(255) | YES | | NULL | |
| rating | varchar(255) | YES | | NULL | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | |
| updated_at | timestamp | NO | | CURRENT_TIMESTAMP | |
| reviewer_name | varchar(255) | YES | | NULL | |
| product_id | int(11) | YES | | NULL | |
+---------------+--------------+------+-----+-------------------+----------------+
mysql> desc products;
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| details | text | NO | | NULL | |
+---------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
當我試圖在審查表作爲外鍵的product_id引用ID在產品表,我發現這個錯誤,什麼我給查詢是:
mysql> ALTER TABLE review ADD FOREIGN KEY (product_id) REFERENCES products(id);
ERROR 1215 (HY000): Cannot add foreign key constraint
請大家幫我出了什麼問題,我怎麼能弄清楚
可能和int 11 – GurV
所以我想現在要做的是 – Karthiga
我改變了它正常工作。謝謝 – Karthiga