zoukankan      html  css  js  c++  java
  • MySQL出现无法删除行记录

    今天mysql在删除一张InnoDB类型的表时,出现错误Error No. 1451

    MYSQL: Cannot delete or update a parent row: a foreign key constraint fails

    解决方法:

    这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。

    SET FOREIGN_KEY_CHECKS = 0;

    执行删除sql语句;
    删除完成后设置 ;
    SET FOREIGN_KEY_CHECKS = 1;



    其他:
    关闭唯一性校验
    set unique_checks=0;
    set unique_checks=1;

    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)
  • 相关阅读:
    Sublime_text 3 安装 Package Control
    sql server cross/outer apply 用法
    sql server pivot/unpivot 行列互转
    sql server利用开窗函数over() 进行分组统计
    小记sql server临时表与表变量的区别
    自己实现各种进制相互转换
    我这样理解js里的this
    js 数组去重
    分布式计算
    START法则
  • 原文地址:https://www.cnblogs.com/qmfsun/p/4838063.html
Copyright © 2011-2022 走看看