gpt4 book ai didi

php - MySQL错误: Error creating table: Cannot add foreign key constraint

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

我正在尝试在两个表之间设置引用,但在加载页面时不断遇到此错误。

Error creating table: Cannot add foreign key constraint

这是“日历”表: calendars table image

这是我当前运行的用于创建表的查询:

CREATE TABLE `'.$classTableName.'`(
classID INT(11) NOT NULL,
name VARCHAR(255) NOT NULL,
users INT(11) NOT NULL,
files INT(11) NOT NULL,
chats INT(11) NOT NULL,
deadlines INT(11) NOT NULL,
calendar INT(11) NOT NULL,
PRIMARY KEY (classID),
FOREIGN KEY (calendar) REFERENCES calendars(classID)
) ENGINE=INNODB;

如有任何帮助,我们将不胜感激! :)

最佳答案

正如 Basmar 所指出的,必须索引calendars.classID

关于php - MySQL错误: Error creating table: Cannot add foreign key constraint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35356069/

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