Today I ran into this problem for the second time in three years… so it took me a while to figure out the solution (with the help of my trusty partners here in the office of course).
It’s quite a common error message :
SQL Error: 1452: Cannot add or update a child row: a foreign key constraint fails
Usually the foreign key data in the query is either blank or references a non-existing record, but in my case everything was fine with the data. Stranger yet, the same code worked on my localhost and only threw this error on the live server.
First I looked at the query itself, which was fine. Then I compared the foreign key definitions with the one in the parent table, and it was identical. After that I asked for some suggestions, and somebody provided the correct answer.