错误 1452 (23000):无法添加或更新子行:从 mysql 5.5 升级到 5.7 时外键约束失败

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails when upgrading from mysql 5.5 to 5.7

我在尝试 运行 在 mysql 5.7 上导入数据时遇到错误,目前正在 mysql 5.5.

完整错误如下:

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (media24.action_item_group, CONSTRAINT FKAC29F3FCFCAFE3B0 FOREIGN KEY (updated_by_employee_id) REFERENCES employee (id))

有问题的基本概述table

 | | created_by_employee_id     | bigint(20)   | YES  | MUL | NULL    |  
 | | updated_by_employee_id     | bigint(20)   | YES  | MUL | NULL    |
 | | exit_reason_id             | bigint(20)   | YES  | MUL | NULL    |
 | | root_action_item_group_id  | bigint(20)   | YES  | MUL | NULL    |
 | | forwarding_contact_no      | varchar(255) | YES  |     | NULL    |
 | | forwarding_email           | varchar(255) | YES  |     | NULL    |
 | | tenant_id                  | bigint(20)   | NO   | MUL | 0       |
 | | employee_job_position_id   | bigint(20)   | YES  | MUL | NULL    |

根据您的问题,这 3 种解决方案中的一种可能对您有所帮助:

1- 您正在导入一个 table(命名为 A),它对其他 table(命名为 B)中的某些字段具有 FK。 由于你的新数据库中没有 table B,每当你想导入 table A 时,它都会显示你设置 FK 时出错。

2- 还要检查您是否尝试向 table 添加行,而 employee table[ 中没有匹配行 (id) =12=]

3- 也不要忘记检查重复值

通过在插入命令之前添加它来关闭它:

SET foreign_key_checks = 0;

然后在插入后将其重新设置:

SET foreign_key_checks = 1;

请注意并确保您知道自己在做什么。