关于mysql中[Err] 1451 -Cannot delete or update a parent row: a foreign key constraint fails
Posted wangjq_china
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于mysql中[Err] 1451 -Cannot delete or update a parent row: a foreign key constraint fails相关的知识,希望对你有一定的参考价值。
mysql> SET FOREIGN_KEY_CHECKS = 0;
Query OK, 0 rows affected (0.02 sec)
mysql> delete from repositories where repo_name = "watch/sinawatch_agent_update";
Query OK, 1 row affected (0.02 sec)
mysql> SET FOREIGN_KEY_CHECKS = 1;
Query OK, 0 rows affected (0.00 sec)
SET FOREIGN_KEY_CHECKS = 0 //关闭外键约束
进行完操作后别忘记了再把外键约束重新打开以下是打开数据库的外键约束:
SET FOREIGN_KEY_CHECKS = 1 //打开外键约束
以上是关于关于mysql中[Err] 1451 -Cannot delete or update a parent row: a foreign key constraint fails的主要内容,如果未能解决你的问题,请参考以下文章
Flask中的(pymysql.err.IntegrityError)(1451,'无法删除或更新父行:外键约束失败...')