关于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 //打开外键约束