1451: Cannot delete or update a parent row: a foreign key constraint fails(无法删除或更新父行:外键约束失败)
MySQL含义
你尝试删除父行或修改其键,但由于存在依赖的子行,外键约束不允许该操作。
原因
被引用的父行仍有子行,且约束的 ON DELETE/UPDATE 使用 RESTRICT/NO ACTION。
解决方法
先删除依赖的子行或将其移到另一个父行下,然后再删除父行。如果需要自动处理,用 ON DELETE CASCADE 或 ON DELETE SET NULL 重新定义约束。查找依赖行:SELECT * FROM child_table WHERE fk_column = value。
同一数据库的其他条目
- 2006MySQL server has gone away(MySQL 服务器已断开)
- 1114The table is full(表已满)
- 1215Cannot add foreign key constraint(无法添加外键约束)
- 1452Cannot add or update a child row: a foreign key constraint fails(无法添加或更新子行:外键约束失败)
- 1366Incorrect string/integer value for column(列的字符串/整数值不正确)
- 1044Access denied for user to database(用户对数据库的访问被拒绝)
- 1264Out of range value for column(列的值超出范围)