This error ( Cannot add or update a child row: a foreign key constraint fails ) is reported in MySQL FK Doc
To add a link between two tables, the condition must match existing data.
This means that if you say table1.id = table2.id , then all identifiers table1 and table2 must match.
To solve this problem, you need to eliminate or fix those lines that do not match.
Example:
table1.id | table2.fk 1 | 1 ok 2 | null error 3 | 4 error if id 4 is not in table1
juergen d
source share