我在添加外鍵votes
時遇到了問題。無法創建FOREIGN KEY MySQL錯誤150
mysql> describe votes;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(11) unsigned | NO | | NULL | |
| video_id | int(11) unsigned | NO | | NULL | |
| vote | int(11) | NO | | NULL | |
+----------+------------------+------+-----+---------+----------------+
mysql> describe user;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| email | varchar(256) | NO | MUL | NULL | |
| password | varchar(32) | NO | | NULL | |
| name | varchar(24) | NO | | NULL | |
+----------+------------------+------+-----+---------+----------------+
Votes.user_id是User.id的外鍵。博特具有相同的時間但是當我運行:
mysql> alter table `votes`
add CONSTRAINT `votes_FK_1`
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
MySQL是拋出一個良好的老150
ERROR 1005 (HY000): Can't create table 'crocko.#sql-6e1_3c5' (errno: 150)
我在做什麼錯?
你有存儲上就已經表中的數據? – Alfabravo
你的數據庫是在MYISAM引擎中嗎? – gks
謝謝陌生人 - 那究竟是什麼。改爲innodb,現在沒事了。 –