MySql数据库插入或更新报错:Cannot add or update a child row: a foreign key constraint fails

具体报错信息:

Cannot add or update a child row: a foreign key constraint fails (`xxx`.`AAA`, CONSTRAINT `tb_competitionmsg_ibfk_2` FOREIGN KEY (`organizerid`) REFERENCES `BBB` (`id`))

报错信息分析:

XXX数据库中的 AAA表 中的 organizerid字段 是BBB表中的id的外键,但是要插入的organizerid值在id中没有匹配成功。

解决:

检查插入的数据是否正确

在BBB表中的id字段中添加上所要插入的值。

猜你喜欢

转载自www.cnblogs.com/ssyh/p/10183678.html