MySQL表中有外键约束时级联删除报错annot delete or update a parent row: a foreign key constraint fails
来源:互联网 发布:福禄克网络官网 编辑:程序博客网 时间:2024/04/29 09:19
做的一个小项目中用到几个表,产品分类表category,产品属性表property和产品表product。删除分类的时候,发现报错
Cannot delete or update a parent row: a foreign key constraint fails。
报这个错误是由于存在外键约束,category中存在来自property和product的外键,或者说property和product有外键指向category,category表被删除了的话,property和product的外键就不知道指向谁了,所以会报错。
解决方法有两种
第一种方法是,增加外键约束时,声明级联删除,具体如把
CONSTRAINT `fk_product_category` FOREIGN KEY (`cid`) REFERENCES `category` (`id`)
改为
CONSTRAINT `fk_product_category` FOREIGN KEY (`cid`) REFERENCES `category` (`id`) ON DELETE CASCADE
第二种方法是,使用触发器,在删除category之前先删除property和product
第二种方法后续再展开
阅读全文
0 0
- MySQL表中有外键约束时级联删除报错annot delete or update a parent row: a foreign key constraint fails
- 级联删除报Cannot delete or update a parent row: a foreign key constraint fails解决方法
- linux系统mysql删除一行报错:Cannot delete or update a parent row: a foreign key constraint fails
- hibernate 级联删除报Cannot delete or update a parent row: a foreign key constraint fails异常
- mysql基础(五) Mysql删除表时,报"Connot delete or update a parent row:a foreign key constraint fails"解决方案
- mysql基础(六) 表删除时,报"Connot delete or update a parent row:a foreign key constraint fails"解决方案二
- [MySQL]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错误号1451-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
- 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
- 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:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
- 表删除时Cannot delete or update a parent row: a foreign key constraint fails 异常处理
- FreeBASIC学习笔记——6.4 可变参数
- 提升SolidWorks打开模型速度的方法
- chmod命令详细用法
- 函数的多个参数va_list, va_start, va_avg, va_end的使用
- Intellij IDEA Mybatis plugin插件破解安装
- MySQL表中有外键约束时级联删除报错annot delete or update a parent row: a foreign key constraint fails
- Koltin数据类之解构申明
- Codeforces Round #451 (Div. 2) C. Phone Numbers
- 二叉树--uva699 二叉树递归遍历
- 环境变量PATH
- 使用Spring的Pageable来实现分页查询
- XML
- JVM的GC机制<一>新生代GC
- redis.conf 配置文件详解