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;
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:
- Mysql error 1452 – Cannot add or update a child row: a foreign key constraint fails
- Solution to error 1452: cannot add or update a child row: a foreign key constraint failures in MySQL
- MYSQL ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
- Mysql error when deleting the table structure: Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails
- MySql ERROR CODE:1215 Cannot add the foreign key constraint
- 1822 – Failed to add the foreign key constraint. Missing index for constraint ‘tb_emp_ibfk_1’ in the
- Failed to add the foreign key constraint. Missing index for constraint ‘stu_ibfk_1’ in the reference
- MySQL failed to add foreign key error 1452
- MySQL error code 1217 (ER_ROW_IS_REFERENCED): Cannot delete or update a parent row: a foreign key co
- MySQL:Foreign key fails with error Error Code: 1452.
- Ora-02292: integrity constraint (XX) violated – child record found foreign key Association, record cannot be deleted
- MySQL error 1451 23000 foreign key exception handling
- Syntax error or access violation: 1071 specified key was too long; max key length is 767 bytes
- Add samba user prompt Failed to add entry for user.
- Add Samba user prompt failed to add entry for user
- MySql 8.x java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
- Txt import MySQL: error 1062 (23000): duplicate entry ‘0’ for key ‘primary’
- mysql Error Code: 1022. Can’t write; duplicate key in table `xxx`
- Solution of duplicate entry ‘value’ for key ‘field name’ in MySQL
- The solution of duplicate entry ‘for key’ primary ‘when inserting data in MySQL