gpt4 book ai didi

MySQL errno 150 尚未解决

转载 作者:行者123 更新时间:2023-11-29 12:59:57 25 4
gpt4 key购买 nike

虽然这是一个重复的问题,我一直在搜索大多数类似的帖子,但没有发现任何有用的内容。这是我的 MySQL SQL 脚本。

CREATE DATABASE IF NOT EXISTS store;
USE store;
CREATE TABLE IF NOT EXISTS Box (
coord VARCHAR (255),
box_id INT UNSIGNED NOT NULL,
img_path VARCHAR (256),
PRIMARY KEY (coord, box_id)
);
CREATE TABLE IF NOT EXISTS Tool (
serial VARCHAR (50),
tool_id INT,
descr VARCHAR (256),
box_id INT UNSIGNED NOT NULL,
tool_state BOOLEAN,
PRIMARY KEY (tool_id),
FOREIGN KEY (box_id) REFERENCES Box(box_id)
);

输出为:第 9 行错误 1005 (HY000):无法创建表“store.Tool”(errno:150)任何建议

最佳答案

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

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.

我猜你必须使用相同数量的外键,在你的代码中,你在表 Box 中使用了 2 个 PK,所以要么只使用 box_id 作为你的 PK,要么将外键添加到表 Tool..

关于MySQL errno 150 尚未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23491339/

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