MySQL建表时出现错误1005
我的表定义:
CREATE TABLE x (
a INT NOT NULL,
FOREIGN KEY (a) REFERENCES a (id) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE = InnoDB;
产生以下错误:
ERROR 1005 (HY000): Can't create table './abc/x.frm' (errno: 150)
这是什么意思?
My table definition:
CREATE TABLE x (
a INT NOT NULL,
FOREIGN KEY (a) REFERENCES a (id) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE = InnoDB;
which produces the following error:
ERROR 1005 (HY000): Can't create table './abc/x.frm' (errno: 150)
What does this mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许这就是原因
来自: http://dev.mysql。 com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
Maybe this is why
from: http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
使用 perror 和“errno”错误号来获取错误消息(错误 150):
use perror with the "errno" error number to get the error message (perror 150):
也许那个 a.id 并不存在。
Probably that a.id doesn't exist.
如果存在重复的外键名称,也会发生这种情况。
举例来说,您有两个非常相似且名称很长的表。 为了“节省”时间,您从第一个表的 CREATE 中复制并粘贴外键名称,然后分心并无法更新表名称中不同的部分。 它们碰巧与另一个表共享外键,从而产生一个或多个相同的外键名称。
您是否注意到,用头撞显示器并不能令人满意?
This also happens if there are duplicate foreign key names.
Say for example that you have two very similar tables with long names. To "save" time, you copy and paste the foreign key names from the first table's CREATE, then get distracted and fail to update the part of the table name that is different. They happen to share a foreign key to another table, resulting in one or more identical foreign key names.
Have you noticed that bashing your head against the monitor isn't as satisfying with an LCD?
当引用的表不使用InnoDB存储格式时也会抛出此错误。
This error is also thrown when the referenced table does not use the InnoDB storage format.