Forum Moderators: open

Message Too Old, No Replies

MySQL Error

         

MrFahad

11:17 am on Nov 21, 2008 (gmt 0)

10+ Year Member



Hello, when i try to delete a record i get this message:

#1451 - Cannot delete or update a parent row: a foreign key constraint fails (`casherzc_realestate/tMobileHomes`, CONSTRAINT `fk_PertMobileHomes` FOREIGN KEY (`Propertyid`) REFERENCES `tProperty` (`Propertyid`))

please help thank you :)

tonynoriega

7:18 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this might be easier to answer if you provide the query statement and maybe table structure.

its hard to tell without the query.

i did however google this real quick and found that its documented:

"Deviation from SQL standards: If ON UPDATE CASCADE or ON UPDATE SET NULL recurses to
update the same table it has previously updated during the cascade, it acts like RESTRICT.
This means that you cannot use self-referential ON UPDATE CASCADE or ON UPDATE SET NULL
operations."

Demaestro

7:24 pm on Nov 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sounds like something is trying to force referential integrety and won't allow you to orphan a record.

What this usually means is there is another table that uses the ID from the record you are trying to delete which is in a separate tables.

An easy example of this is you have two tables.

User
u_id ¦ name ¦ state_id

State
State_id ¦ state_name

If you were to delete a state, but the user table still has someone using that state_id then the DB will want you to either give that user a new state_id, or it will want you to delete that state_id before it will let you delete the record from the state table.

Do you know if ids from the record you are deleting are used in another table?