MySQL won't let me delete rows

Hi there,

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 (rayku_db.shout, CONSTRAINT shout_ibfk_1 FOREIGN KEY (poster_id) REFERENCES user (id))


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?

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.

if you normally want to keep them, then you shouldn’t have declared the FK with cascading deletes

that’s why I don’t declare them.

but every now and then I get a client in the same situation as the OP.