MySQL failed to add foreign key: SQL 1452 cannot add or update a child row:a foreign key constraint fails

Today, adding a foreign key to one of the two existing tables encountered the following error:
sql 1452 Cannot add or update a child row:a foreign key constraint fails
The reason:
The foreign key set does not match the primary key value of the corresponding table.
Solutions:
Find the mismatched value changes.
Or empty both tables of data.
 
The original link
 
It is my personal understanding that the cause should be (untested) :
1. The names of fields in the two tables are different;
2. The types of fields in two tables are different (such as an int and a VARCHar);
3. According to the original author’s idea, there should be data in the two tables, and the data are different;

Read More: