gpt4 book ai didi

MySql 错误 150 - 外键

转载 作者:行者123 更新时间:2023-11-29 18:54:13 25 4
gpt4 key购买 nike

当我执行以下两个查询时(我已将它们精简为绝对必要的):

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)

我的错误到底在哪里?我盯着这个看了半个小时也没找到他。

最佳答案

来自FOREIGN KEY Constraints

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,因为其他一切看起来都正常。

编辑:从同一页面 -

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

关于MySql 错误 150 - 外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44224490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com