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))

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 mysql报:1452