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)
  • 相关阅读:
    K8s--09 编写mysql的持久化deployment
    K8s--08 prometheus监控
    K8s--07 configMap资源
    K8s--06 K8s数据持久化
    k8S--05 K8s控制器类型
    k8s--04 部署harbor作为k8s镜像仓库
    K8s--03 资源类型
    K8s--02 K8S部署
    K8s--01 Kubernetes简介
    video2gift环境安装(Theano等)
  • 原文地址:https://www.cnblogs.com/qmfsun/p/4838063.html
Copyright © 2011-2022 走看看