[英]MySQL Error: Error creating table: Cannot add foreign key constraint
I'm trying to set up a reference between two tables, and I keep running into this error when I load the page. 我试图在两个表之间建立引用,并且在加载页面时一直遇到此错误。
Error creating table: Cannot add foreign key constraint
This is the 'calendars' table: calendars table image 这是“日历”表: 日历表图像
And this is the current query I am running to create the table: 这是我正在运行以创建表的当前查询:
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;
Any help would be appreciated! 任何帮助,将不胜感激! :)
:)
正如Basmar指出的那样,必须索引calendars.classID
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.