| 
	
 | 
 Posted by IchBin on 07/25/06 16:03 
laredotornado@zipmail.com wrote: 
> Hi, Using PHP 4, MySQL 4, I'm getting an error when executing an SQL 
> statement: 
>  
> Statement failed "DELETE FROM USERS WHERE USER_ID = 17" - Cannot delete 
> or update a parent row: a foreign key constraint fails 
>  
> How can I query the SQL database to figure out what parent row the 
> statement is complaining about? 
>  
> Thanks,- 
>  
  For those encountering the problem " ERROR 1216: Cannot add or update  
a child row: a foreign key constraint fails", it actually means what it  
says! Some row in the child does not comply with the constraint, correct  
the problem. 
  You find the rows like this: 
  select child.id from child left join parent on  
(child.parent_id=parent.id) where child.id is not null and parent.id is  
null; 
 
http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html 
 
 
Thanks in Advance... 
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us 
__________________________________________________________________________ 
 
'If there is one, Knowledge is the "Fountain of Youth"' 
-William E. Taylor,  Regular Guy (1952-)
 
  
Navigation:
[Reply to this message] 
 |