解决Cannot delete or update a parent row: a foreign key constraint fails (`current_source_products`.`product_storage`, CONSTRAINT `product_storage_ibfk_3` FOREIGN KEY (`InOperatorID`)
出现这个异常的原因是因为设置了外键,造成无法更新或删除数据。
1、通过设置FOREIGN_KEY_CHECKS变量来避免这种情况
删除前设置
SET FOREIGN_KEY_CHECKS=0;
删除完成后
SET FOREIGN_KEY_CHECKS=1;
这样虽然可以解决异常问题,但是表连结问题依然存在,如删除了外键中的一行,其他包含该行的数据应该也对应删除才行。
2、外键的级联删除
如果父表中的记录被删除,则子表中对应的记录自动被删除。
父表——被外键引用的表
子表——引用父表中的键作为外键的表
ALTER TABLE `current_source_products`.`product_storage`
-> ADD CONSTRAINT `product_storage_ibfk_3`
-> FOREIGN KEY (`InOperatorID`)
-> REFERENCES `current_source_products`.`staff` (`StaffID`)
-> ON DELETE CASCADE
-> ON UPDATE CASCADE;
3、外键的选项
ON DELETE CASCADE 级联
ON DELETE RESTRICT 当父表中删除对应记录时,首先检查该记录是否有对应外键,如果有则删除外键在子健中的记录
ON DELETE SET NULL 子健中对应记录设置为空
ON DELETE NO ACTION 同restrict
解决Cannot delete or update a parent row: a foreign key constraint fails (`current_source_products`.`product_storage`, CONSTRAINT `product_storage_ibfk_3` FOREIGN KEY (`InOperatorID`)的更多相关文章
- 【转】 #1451 - Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
转载地址:http://blog.csdn.net/donglynn/article/details/17056099 错误 SQL 查询: DELETE FROM `zmax_lang` WHERE ...
- 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 ...
- 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 ...
- 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 ...
- 【转】表删除时 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 原因是主表中还包含字表的数据, ...
- ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails ()
centos7.5 删除表空间文件失败 问题: mysql> alter table country discard tablespace; ERROR 1451 (23000): Cannot ...
- 表删除时 Cannot delete or update a parent row: a foreign key constraint fails 异常处理
有两张表,结构如下: t_item: t_bid: id int id int n ...
- 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 ...
随机推荐
- javascript 中的借鸡生蛋
如题所说,其实指的是 js 中的内置函数和 apply 的结合使用.这种用法很讨巧,读过 jQuery 源码的小伙伴都知道,它在里面被应用的非常广泛和精妙! 梨子:找出一个数组中的最大值和最小值 普遍 ...
- Android Token的使用学习
学习Token Token是什么? Token是服务端生成的一串字符串,以作客户端进行请求的一个令牌,当第一次登录后,服务器生成一个Token便将此Token返回给客户端,以后客户端只需带上这个Tok ...
- centos下搭建lamp环境
1 在线安装所有的服务 yum -y install httpd mysql mysql-server php php-mysql postgresql postgresql-server php-p ...
- 设计模式(2)--单例模式(Singleton Pattern)
概述 一个类能返回对象一个引用(永远是同一个)和一个获得该实例的方法(必须是静态方法,通常使用getInstance这个名称):当我们调用这个方法时,如果类持有的引用不为空就返回这个引用,如果类保持的 ...
- ssi项目(1)环境搭建
1.环境准备 导包(jdk1.8只支持spring4.0以上的版本) mysql驱动包 c3p0驱动包 mybatis包 spring-core.spring-aop.spring-web.sprin ...
- JavaScript 基础知识之对比记忆学习
1. alter修改(易写混),alert警告 alert 函数语法:alert(str);str字符串用单引号或双引号隔开 2.标识符和关键字 标识符:由不以数字开头的字母.数字.下划线.$组成. ...
- Plupload上传组件 + javaweb实现上传源码以及DEMO
Plupload 是一个Web浏览器上的界面友好的文件上传模块,可显示上传进度.图像自动缩略和上传分块.可同时上传多个文件: 上网找了很多Plupload的DEMO都无法正常使用, 而且Pluploa ...
- SQL Server中cursor的使用步骤
参考文章: http://www.cnblogs.com/knowledgesea/p/3699851.html http://www.cnblogs.com/moss_tan_jun/archive ...
- 2.4G/5G频段WLAN的模式、带宽、协商速率
2.4G频段 5G频段
- ios安装app提示【未受信任的企业级开发者】。在设置中信任此开发者
最近在测试app,ios安装app后点击提示如下图: 解决方法: 1 点击 [设置] >[通用] >[设备管理] 2 点击企业级应用 > 信任该开发者 > 信任.设置之后 ...