Dao层测试报错

来源:4-1 Dao层之新增店铺

慕雪7026556

2018-10-04

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_shop, CONSTRAINT fk_shop_shopcate FOREIGN KEY (shop_category_id) REFERENCES tb_shop_category (shop_category_id))

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: INSERT INTO tb_shop(owner_id, area_id, shop_category_id, shop_name, shop_desc, shop_addr, phone, shop_img, priority, create_time, last_edit_time, enable_status, advice) VALUES (?,?,?,?, ?,?,?,?,?, ?,?, ?,?)

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (o2o.tb_shop, CONSTRAINT fk_shop_shopcate FOREIGN KEY (shop_category_id) REFERENCES tb_shop_category (shop_category_id))

; SQL []; Cannot add or update a child row: a foreign key constraint fails (o2o.tb_shop, CONSTRAINT fk_shop_shopcate FOREIGN KEY (shop_category_id) REFERENCES tb_shop_category (shop_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_shop, CONSTRAINT fk_shop_shopcate FOREIGN KEY (shop_category_id) REFERENCES tb_shop_category (shop_category_id))

写回答

1回答

翔仔

2018-10-05

同学好,错误比较明显 店铺表里的店铺类别id在店铺类别表里不存在,请在店铺类别表里创建对应的id 此类mysql错误非常简单,希望同学能锻炼下这类问题独立处理的能力,为以后找工作做好准备

0
2
翔仔
回复
慕雪7026556
一般尝试把caused by 相关的信息进行分析,也可以贴到网上就能找到答案
2018-10-06
共2条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程