mysql删除有外链索引数据,Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
mysql删除有外链索引数据
Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
查询:DELETE FROM `goods` WHERE `goods_id` = '11'
错误代码: 1451
Cannot delete or update a parent row: a foreign key constraint fails (`webDB`.`goods_properties_detail`, CONSTRAINT `FK_rip_43` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`goods_id`))
以上是因为,该条记录的某个字段作为innodb的另外一个表的外链。而在删除操作时会自动检查外链。
解决办法一:先判断删除关联数据,然后再删除(这样比较符合业务逻辑比较安全)。
解决办法二:不检查外链,设置FOREIGN_KEY_CHECKS变量:
SET FOREIGN_KEY_CHECKS = 0;
DELETE FROM `goods` WHERE `goods_id` = '11'
删除完成后设置
SET FOREIGN_KEY_CHECKS = 1;
ps:关闭唯一性校验
set unique_checks=0;
set unique_checks=1;
mysql删除有外链索引数据,Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法的更多相关文章
- mysql 在删除数据出现Cannot delete or update a parent row: a foreign key constraint fails 这个该如何解决
mysql 在删除数据出现Cannot delete or update a parent row: a foreign key constraint fails 这个该如何解决 可以这样解决: S ...
- Mysql - 删除表时出现: Cannot delete or update a parent row: a foreign key constraint fails
现象 MySQL在删除一张表时出现 ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint ...
- MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误
前几天,发现从库挂了,具体报错信息如下: 分析思路 1. 因为我采用的是选择性复制,只针对以下几个库进行复制: card,upay,deal,monitor,collect.所以,不太可能出现对于sa ...
- 【转】表删除时 Cannot delete or update a parent row: a foreign key constraint fails 异常处理
转载地址:http://lijiejava.iteye.com/blog/790478 有两张表,结构如下: t_item: t_bid: id ...
- Hibernate级联删除时:Cannot delete or update a parent row: a foreign key constraint fails异常
在删除主表数据时,报了一个异常 Cannot delete or update a parent row: a foreign key constraint fails 原因是主表中还包含字表的数据, ...
- MySQL:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
MySQL在删除一张表时出现 ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fa ...
- Mysql之1451 - Cannot delete or update a parent row: a foreign key constraint fails...解决办法记录
今天使用delete语句删除一张表中的一条信息时,提示了这么一个错误:1451 - Cannot delete or update a parent row: a foreign key constr ...
- 表删除时 Cannot delete or update a parent row: a foreign key constraint fails 异常处理
有两张表,结构如下: t_item: t_bid: id int id int n ...
- MYSQL: Cannot delete or update a parent row: a foreign key constraint fails
这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据.可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况. SET FOREIGN_KEY_CHE ...
随机推荐
- python操作数据库PostgreSQL
1.简述 python可以操作多种数据库,诸如SQLite.MySql.PostgreSQL等,这里不对所有的数据库操作方法进行赘述,只针对目前项目中用到的PostgreSQL做一下简单介绍,主要包括 ...
- 扩展Spring切面
概述 Spring的切面(Spring动态代理)在Spring中应用十分广泛,例如还有事务管理,重试等等.网上介绍SpringAop源码很多,这里假设你对SpringAop有基本的了解.如果你认为Sp ...
- mvc 实现超时弹窗后跳转
为了实现保持登录状态,可以用cookie来解决这一问题 假设过期时间为30分钟,校验发生在服务器,借助过滤器,可以这样写 public class PowerFilter : AuthorizeAtt ...
- 【巷子】---vue基于mint-ui三级联动---【vue】
一.基本配置 https://github.com/modood/Administrative-divisions-of-China 三级联动数据地址 二.vue基本配置 1.cnpm install ...
- [实战]MVC5+EF6+MySql企业网盘实战(2)——验证码
写在前面 断断续续,今天算是把验证码的东东弄出来了. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网盘实战(1) [实战]MVC5 ...
- related Field has invalid lookup: icontains 解决方法
models.py 文件 # coding:utf8 from django.db import models class Book(models.Model): name = mod ...
- 虚拟机中安装Ubuntu 16.04
1.安装vmware软件(虚拟机管理软件) https://blog.csdn.net/salmon_zhang/article/details/79468918 2.安装Ubuntu https:/ ...
- 日期 date +%F-%T-%N
date +%F-%T-%N 2016-03-24-14:40:13-997433641 %% a literal % %a locale's abbreviated weekday nam ...
- 12 jmeter性能测试实战--web程序
项目背景 项目:XX网站环境:Windows需求:并发登录的性能测试场景:1s增加2个线程,运行2000次(线程数20,Ramp-Up seconds 10,循环次数100).分别看20.40.60并 ...
- 007-ant design 对象属性赋值,双向绑定
1.state对象属性赋值 设对象为 state={ datavalue:{ id:'', name:'', }, } 修改对象属性为: SetName=(e)=>{ let val=e.tar ...