我在 table 上添加外键时遇到问题votes
。
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 的外键。但是当我运行时,Bot 有相同的时间:
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)
我究竟做错了什么?