Cannot add or update a child row: a foreign key constraint fails mysql报:1452

  • 今天给表中的数据创建外键时,一直报

Cannot add or update a child row: a foreign key constraint fails (company.userinfo, CONSTRAINT afsfasd FOREIGN KEY (ded) REFERENCES detail (ded))


这是因为你在创建 外键时,表中已经有了数据,并且两个表中的外键不一致,我的观点是:

①清空两张表,然后再创建外键。

②把两个表中对应的外键列检查一下,确保主表中的外键的列,在另一个表中都有对应的数据。

希望可以帮助到大家!

在这里插入图片描述

发布了25 篇原创文章 · 获赞 22 · 访问量 5408

猜你喜欢

转载自blog.csdn.net/weixin_42893085/article/details/104918471