system — 2010-11-27T16:07:22-05:00 — #1
I am trying to clean out my database by deleting entries in certain tables. However, I am constantly getting a MySQL error message saying that I can't do so.
Is there any way I can work around this?
1451 - Cannot delete or update a parent row: a foreign key constraint fails (
shout_ibfk_1 FOREIGN KEY (
dr_john — 2010-11-27T16:12:46-05:00 — #2
try using the on delete cascade option, this will remove the orphan rows that would be left in another table with no parent for their foreign key. Are you sure, of course, that you want to delete these rows in the other table as well?
system — 2010-11-27T16:16:43-05:00 — #3
or disable the foreign keys first.
Personally I don't like using cascading deletes because you could accidentally delete rows in other tables that you would normally want to keep.
r937 — 2010-11-27T17:02:12-05:00 — #4
if you normally want to keep them, then you shouldn't have declared the FK with cascading deletes
system — 2010-11-27T18:55:25-05:00 — #5
that's why I don't declare them.
but every now and then I get a client in the same situation as the OP.