程序员
董欣欣的个人博客

mysql删除报错Cannot delete or update a parent row

mysql> delete from repositories where repo_name = “watch/sinawatch_agent_update”;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (rhodecode.repo_to_perm, CONSTRAINT repo_to_perm_ibfk_3 FOREIGN KEY (repository_id) REFERENCES repositories (repo_id))
这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。
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)
未经允许不得转载:董不董 - 董欣欣的个人博客 » mysql删除报错Cannot delete or update a parent row
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

www.dongxinxin.cn 技术博客

联系我关于我