1553: Cannot drop index needed in a foreign key constraint(无法删除外键约束所需的索引)
MySQL含义
您试图删除外键约束所需的索引。InnoDB 不允许删除 FK 所依赖的索引。
原因
在 InnoDB 中,每个外键都需要在其引用列上有索引。用 DROP INDEX 删除该索引会使 FK 约束失去支撑,因此被拒绝。通常在重组表(清理索引)时遇到。
解决方法
先删除外键约束,再删除索引:ALTER TABLE my_table DROP FOREIGN KEY fk_name; 然后 DROP INDEX idx_name ON my_table; 如有需要,重新创建 FK,使其依赖另一个合适的索引。列出现有 FK:SELECT constraint_name, table_name FROM information_schema.key_column_usage WHERE referenced_table_name IS NOT NULL;
同一数据库的其他条目
- 1129Host 'host' is blocked because of many connection errors(主机 'host' 因连接错误过多而被阻止)
- 1194Table 'name' is marked as crashed and should be repaired(表 'name' 被标记为已崩溃,应当修复)
- 1615Prepared statement needs to be re-prepared(预处理语句需要重新准备)
- 3948Loading local data is disabled; this must be enabled on both the client and server sides(加载本地数据已禁用;必须在客户端和服务器端同时启用)
- 1075Incorrect table definition; there can be only one auto column and it must be defined as a key(表定义不正确;只能有一个自增列,且必须将其定义为键)
- 1055Expression not in GROUP BY (only_full_group_by)(表达式不在 GROUP BY 中)
- 1267Illegal mix of collations(非法的排序规则混用)