I also got this error: "Cannot add or update a child row: a foreign key constraint fails". I got the error when adding a new row to the parent table
The problem was that the foreign key constraint had been defined on the parent table instead of the child table.