tb_product_img 外键问题
来源:8-1 商品添加之Dao层的实现
慕姐3071627
2020-03-24
报错
Caused by: java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (myshop.tb_product_img, CONSTRAINT fk_proimg_product FOREIGN KEY (product_id) REFERENCES tb_product (product_id))
tb_product_img的myaql代码
CREATE TABLE tb_product_img(product_img_id int(20) NOT NULL auto_increment,img_addr VARCHAR(2000) NOT NULL,img_desc VARCHAR(2000) DEFAULT NULL,priority int(2) DEFAULT ‘0’,create_time datetime DEFAULT NULL,product_id int(20)DEFAULT NULL,
PRIMARY KEY(product_img_id),
constraint fk_proimg_product foreign key(product_id) references tb_product(product_id)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
tb_product代码
CREATE TABLE tb_product(product_id int(100) NOT NULL auto_increment,product_name varchar(100) NOT NULL,product_desc VARCHAR(2000) DEFAULT NULL,img_addr varchar(2000) default ‘’,normal_price varchar(100) default null,promotion_price varchar(100) default null,priority int(2) not null default’0’,create_time datetime DEFAULT NULL,last_edit_time datetime DEFAULT null,enable_status int(2) NOT NULL DEFAULT’0’,product_category_id int(11) default null,shop_id int(20) not null default’0’,
PRIMARY KEY(product_id),
constraint fk_product_shop foreign key(shop_id) references tb_shop(shop_id),
constraint fk_product_procate foreign key(product_category_id) referencestb_product_category(product_category_id)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
我感觉没有错啊 可是就是找不出原因,麻烦老师帮忙看看
3回答
-
qq_蓝骏毅_04076633
2020-07-14
o2o`.`tb_product_img`, CONSTRAINT `fk_proimg_product` FOREIGN KEY (`product_id`) REFERENCES `tb_product` (`product_id`))
怎么解决的
00 -
慕姐3071627
提问者
2020-03-24
解决了
022020-03-25 -
慕姐3071627
提问者
2020-03-24

报错图
00
相似问题
