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错误非常简单,希望同学能锻炼下这类问题独立处理的能力,为以后找工作做好准备
022018-10-06
相似问题