简体   繁体   English

MySQL错误:创建表时出错:无法添加外键约束

[英]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.

相关问题 PHP MySQL错误创建表:无法添加外键约束 - PHP MySQL Error creating table: Cannot add foreign key constraint MySQL错误代码1215:无法在ALTER TABLE上添加外键约束:Mysql - MySQL Error Code 1215: Cannot add foreign key Constraint on ALTER TABLE : Mysql MySQL 错误:无法添加外键约束(PrestaShop 模块) - MySQL error: Cannot add foreign key constraint (PrestaShop module) 一般错误:1215 无法添加外键约束,Laravel 5 & MySQL - General error: 1215 Cannot add foreign key constraint, Laravel 5 & MySQL Mysql错误添加外键时无法添加外键约束 - Mysql error Cannot add foreign key constraint when i add foreign key 无法在laravel错误中添加外键约束 - Cannot add foreign key constraint in laravel error 向Laravel中的同一表添加外键的问题-错误:“无法添加外键约束” - Problem with add a foreign key to same table in Laravel - Error : “Cannot add foreign key constraint” 添加外键约束时无法更新子表:错误:无法添加或更新子行:外键约束失败 - unable to update a child table when a foreign key constraint is added: error :Cannot add or update a child row: a foreign key constraint fails mysql错误错误SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败? - mysql error error SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails? 无法添加或更新子行,外键约束失败,mysql错误号:1452 - cannot add or update a child row a foreign key constraint fails mysql Error Number: 1452
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM