That happens in one of two ways:
1- You're trying to add a record to the child table and you used a value for the foreign key that doesn't exist in the parent table's primary key.
In this case, double check that the value exists in the parent table. Perhaps you're entering a parent and children records, but the parent record failed to be added. You'll have to stop in this case instead of ignoring the error and continuing with adding the children.
2- Your tables don't have referential integrity like ON DELETE CASCADE
and you deleted a record from the parent table, then you're trying to update a record from the child table that has its foreign key referencing the delete record from the parent table.
In this case, you may want to delete the children instead of updating them. Consider adding referential integrity to your tables.