Alright, a lot of people probably get this a lot with mySQL. Here’s the fact, there is a 99.999% chance your code is wrong and there is not a bug with mySQL.
The solution to this problem is actually really easy to figure out, it’s just that SQL has a horrible debuging scripts which make it a pain to figure out.
Just type:
Show innoDB status;
Read under the section: Latest Foreign Key Error, and there you go! Your problem explained! Just read it two or three times if you don’t get it. Trust me it helps a lot.
Happy coding