商品添加报错,调试信息如下,翔仔麻烦看一下
来源:8-6 商品添加之前端实现下

慕勒4553688
2020-04-24
{success=false, errMsg=com.imooc.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 dsf
FOREIGN KEY (product_category_id
) REFERENCES tb_shop_category
(shop_category_id
))
The error may involve com.imooc.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 dsf
FOREIGN KEY (product_category_id
) REFERENCES tb_shop_category
(shop_category_id
))
; SQL []; Cannot add or update a child row: a foreign key constraint fails (o2o
.tb_product
, CONSTRAINT dsf
FOREIGN KEY (product_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_product
, CONSTRAINT dsf
FOREIGN KEY (product_category_id
) REFERENCES tb_shop_category
(shop_category_id
))}
2回答
-
同学好,
Cannot add or update a child row: a foreign key constraint fails (o2o.tb_product, CONSTRAINT dsf FOREIGN KEY (product_category_id) REFERENCES tb_shop_category (shop_category_id))
你这个tb_product表里面的product_category_id为什么要去关联tb_shop_category里面的shop_category_id?应该是tb_product_category里面的product_category_id才对吧。。而且 你得确保tb_product里面得product_category_id在tb_product_category里面存在
012020-04-26 -
weixin_慕瓜9035920
2020-04-24
应该是product_category_id不对,你填一个你数据库表中有的product_category_id试试。
122020-04-24