Can';t创建外键MySQL错误150
在表Can';t创建外键MySQL错误150,mysql,Mysql,在表投票中添加外键时,我遇到了一个问题 mysql> describe votes; +----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+------------------+------+-----+---------+------
投票
中添加外键时,我遇到了一个问题
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 | |
+----------+------------------+------+-----+---------+----------------+
vows.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)
我做错了什么?您需要检查表中是否存储了任何数据。。如果是,则需要删除它们 或者,如果您的MySQL DB引擎是MyISAM,则在创建表后将无法添加外键
您可以检查如何将其更改为InnoDB。您已经在表中存储了数据吗?您的数据库是否在MYISAM引擎中?谢谢您,陌生人-这正是事实。改为innodb,现在一切都好了。Tat很好:)抱歉,无法回答您不可避免的干扰:(就是这样-一些桌子上有MyISAM,一些桌子上有innodb。谢谢您的帮助。