Home mysql # 1452 - Cannot add or update a child row: a foreign...

# 1452 – Cannot add or update a child row: a foreign key constraint fails

Author

Date

Category

Hello. Can’t figure out why the table is not being imported into phpmyadmin.
Structure:
Products table

Category table

I’m trying to import data from an xml dump of another table (it is identical with this one), but an error comes out

All categories with the same ID are in the database. Why can’t he tie them?

Issue resolved


Answer 1, authority 100%

The server will not invent anything. If he says that there are no corresponding records in the parent table, then they really do not exist. Complete your request

SELECT child.reference_field
FROM child
LEFT JOIN parent ON child.reference_field = parent.reference_field
WHERE parent.reference_field IS NULL

and see which values ​​are missing.

PS. If you have a child table in XML, it’s better to import it into an unrelated temporary or static one, and then see what records the problem is with.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions