UT测试报错
来源:8-7 商品编辑之后端开发上
慕仰5218754
2019-05-24
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.imooc.o2o.dao.ProductDao.updateProduct-Inline
The error occurred while setting parameters
SQL: UPDATE tb_product SET product_name=?, product_category_id=? WHERE product_id = ? AND shop_id=?
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
))
; SQL []; 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
))
写回答
2回答
-
慕沐1441344
2021-05-01
mark
00 -
翔仔
2019-05-25
同学好,错误非常明显,你的tb_product里面的product_category_id并没有在tb_product_category表里创建。。违反了主外键的约束。。
022019-05-27
相似问题