Navicat 1452 error when setting foreign keys

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.