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)
  • 相关阅读:
    Python校验文件MD5值
    no acceptable C compiler found in $PATH解决办法
    PRD是什么
    项目中PO、PM的职责区分
    vue-cli中打包之后css加载顺序有错
    vue-cli中打包图片路径错误
    vue2.0的父子组件数据传递
    vue中style的用法
    vue中class的用法
    angular淘宝购物车案例
  • 原文地址:https://www.cnblogs.com/qmfsun/p/4838063.html
Copyright © 2011-2022 走看看