MySQL Error 1217
SQLSTATE: 23000 (ER_ROW_IS_REFERENCED) Cannot delete or update a parent row: a foreign key constraint fails
Comments
Ricky Jan 16, 2008 |
||
This error occurs when you are trying to delete/update a record or column which is referenced as foreign key in some child table and that child table has the value referring to the record you are deleting/updating and while defining the foreign key you have defined it as ON DELETE RESTRICT/ON UPDATE RESTRICT. e.g. Lets assume that we have two table say Table1 and Table2. Table2 has one column say 'name' which has a foreign key reference to Table1's column say 'name'. We have Defined this foreign key as ON DELETE RESTRICT/ON UPDATE RESTRICT. Now say we have one record in Table1's 'name' column as 'XYZ'. And Table2's 'name' column has some record related to this value 'XYZ'. In this scenario if you try to delete/update 'XYZ' from Table1 then you will get this error in return and your data will not be deleted/updated. (P.S. : Foreign Key constraints works wiht InnoDB only so both of your tables should be InnoDB) |
||