300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Mysql添加数据时失败 Cannot add or update a child row: a foreign key constraint fails

Mysql添加数据时失败 Cannot add or update a child row: a foreign key constraint fails

时间:2020-09-25 12:08:54

相关推荐

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 (`zy_test`.`order_item`, CONSTRAINT `order_item_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)

原因:

设置的外键与外键对应的表的主键值不匹配(换句话说你添加外键值在他所对的表中不存在)。

解决方法:

找出不匹配的值修改。

或者清空两表数据。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。