请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师,在验证商品添加的service中报错,dao层验证都是OK的呢

com.myself.o2o.exceptions.ProductOperationException: 创建商品失败org.springframework.dao.DataIntegrityViolationException: 

### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`o2o`.`tb_product`, CONSTRAINT `fk_product_procate` FOREIGN KEY (`product_category_id`) REFERENCES `tb_product_category` (`product_category_id`))

### The error may involve com.myself.o2o.dao.ProductDao.insertProduct-Inline

### The error occurred while setting parameters

### SQL: INSERT INTO   tb_product(product_name,product_desc,img_addr,   normal_price,promotion_price,priority,create_time,   last_edit_time,enable_status,product_category_id,   shop_id)   VALUES   (?,?,?,   ?,?,?,?,   ?,?,?,   ?)

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`o2o`.`tb_product`, CONSTRAINT `fk_product_procate` FOREIGN KEY (`product_category_id`) REFERENCES `tb_product_category` (`product_category_id`))

; ]; Cannot add or update a child row: a foreign key constraint fails (`o2o`.`tb_product`, CONSTRAINT `fk_product_procate` FOREIGN KEY (`product_category_id`) REFERENCES `tb_product_category` (`product_category_id`)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`o2o`.`tb_product`, CONSTRAINT `fk_product_procate` FOREIGN KEY (`product_category_id`) REFERENCES `tb_product_category` (`product_category_id`))


正在回答 回答被采纳积分+3

1回答

翔仔 2018-09-06 00:04:51

同学好,错误比较明显Cannot add or update a child row: a foreign key constraint fails (`o2o`.`tb_product`, CONSTRAINT `fk_product_procate` FOREIGN KEY (`product_category_id`) REFERENCES `tb_product_category` (`product_category_id`))

违反了外键约束,添加商品的时候,添加了一个不存在的商品类别id,即该商品类别id不在tb_product_category里面存在,请调试下原因

1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信