The admin table has fields Admin_name and admin_realname. The Notice table has field admin_name. Previously, the Admin_name foreign key in the notice table was the admin_name of the admin table, and now wants to change to admin_realname, with the same data type and field length, but with a hint of 1452 error, as shown in.
Then Baidu a bit, got a reliable answer:
This is because the table sets a foreign key constraint, and you try to insert a value that does not exist in the table record of the foreign key field , it will report 1452 errors.
For example A, b two tables, a table foreign key ID value from the ID of Table B. When you insert a record in Table A, the ID field uses a value that is not within the range of the B table ID value, and this error is reported.
then I realized, because there are two records in the notice table, changed the foreign key, but the table has a record value is not within the range of Admin_realname, so the error. I changed the contents of the record and then modified the foreign key to succeed.
Sanding original, reproduced please mark, thank you~
Navicat 1452 error when setting foreign keys