![](/img/trans.png)
[英]1822, "Failed to add the foreign key constraint. Missing index for constraint
[英]MySQL on empty DB with no FKs can't create table: Failed to add the foreign key constraint. Missing index for constraint
我删除了数据库中的所有表,但不得不使用
foreign_key_checks=0<\/code>因为引用另一个表的表没有被删除。
现在我启用了外键检查,我无法在空数据库中创建
users<\/code>表。
我觉得有一个悬挂的 FK 约束。 我删除了数据库并重新创建了相同的结果。
[HY000][1822] Failed to add the foreign key constraint. Missing index for constraint 'apiCalls_users_Id_fk' in the referenced table 'users'
在另一个引用此数据库中的约束的数据库(!)(另一个模式!)中有另一个约束。 (由ORM自动错误创建)
我已经通过查看information_schema.KEY_COLUMN_USAGE
并运行查询CONSTRAINT_NAME LIKE '%apiCalls%'
来查找引用的内容...
有趣。
我有一个类似的问题。 它确实是由放置在另一个数据库中的约束引起的,并且是指您尝试创建的表的不同数据库和表名。
找到阻止创建特定表的约束的名称(在 #1822 错误中输出)后,您需要找到它来自的数据库(参见上面的 Seregwethrin 的帖子)。
然后您需要删除(或编辑)约束。
ALTER TABLE `different_table_name`
DROP FOREIGN KEY `id_name_fk`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.