MySQL Forums
Forum List  »  InnoDB

Re: error 1452 "cannot add or update a child row: foreign key constaint fails"
Posted by: Mostafa Othman
Date: July 26, 2008 03:13PM

Hi,
I had the same problem but it was solved as follows:
1-Before assigning a table column as Foreign key, you should MAKE SURE that it contains at least on VALID data, I mean a VALID values in the table column which it will reference to.
On the other hand, if it is empty column you won't face any problem, as the problem arise when it contains no data related to the column which it will point to.

Example:
table: exam
id = 1;
no_question=20;

table:question (had a foreign key (exam.id) that references to exam.id)
ques.id = 1;
exam_id: 1 (it should contains at least ONE VALID data in column (exam.id), such as 1) -----> exam.id

for more information have a look at following link:

http://myownthesis.blogspot.com/2007/10/foreign-key-in-mysql-error-1452-and.html

Thanks.



Edited 1 time(s). Last edit at 07/31/2008 06:16AM by Mostafa Othman.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.