0

我的表定义:

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)

这是什么意思?

4

5 回答 5

4

也许这就是为什么

如果您重新创建已删除的表,则它必须具有符合引用它的外键约束的定义。如前所述,它必须具有正确的列名和类型,并且必须在引用的键上具有索引。如果这些不满足,MySQL 返回错误号 1005 并在错误消息中引用错误 150。

来自:http ://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

于 2009-06-16T20:09:20.623 回答
3

使用带有“errno”错误号的perror来获取错误消息(perror 150):

MySQL错误代码150:外键约束形成错误

于 2009-06-16T20:08:46.723 回答
1

可能那个 a.id 不存在。

于 2009-06-16T20:07:59.097 回答
1

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?

于 2009-11-26T06:07:07.523 回答
1

当引用的表不使用 InnoDB 存储格式时也会抛出此错误。

于 2016-03-23T10:54:01.870 回答