MySql错误150 - 外键 [英] MySql Error 150 - Foreign keys

查看:154
本文介绍了MySql错误150 - 外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

When I execute the follow two queries (I have stripped them down to absolutely necessary):

mysql> CREATE TABLE foo(id INT PRIMARY KEY);
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE bar ( id INT, ref INT, FOREIGN KEY (ref) REFERENCES foo(id)) ENGINE InnoDB;

我得到以下错误:
错误1005(HY000):无法创建表'./test/bar.frm'(errno:150)

I get the following error: ERROR 1005 (HY000): Can't create table './test/bar.frm' (errno: 150)

****是我的错误?我还没有找到他,而盯着这半个小时。

Where the **** is my error? I haven't found him while staring at this for half an hour.

FOREIGN KEY 约束条件
$ b

From FOREIGN KEY Constraints


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

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.



我怀疑是因为你没有创建 foo 作为InnoDB,因为其他一切看起来都不错。

My suspicion is that it's because you didn't create foo as InnoDB, as everything else looks OK.

编辑:从同一页面 -

from the same page -


这两个表都必须是InnoDB表,不是TEMPORARY表。

Both tables must be InnoDB tables and they must not be TEMPORARY tables.

这篇关于MySql错误150 - 外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆