报错
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;
我感觉没有错啊 可是就是找不出原因,麻烦老师帮忙看看
SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需
了解课程