Connecting Tech Pros Worldwide Help | Site Map

Mysql Using Navicat (error --- Foreign Key Fails)

Newbie
 
Join Date: Jun 2007
Posts: 29
#1: Jun 18 '07
Hi I am new at ASP and MYSQL.

I am Using Navicat to access MYSQL database.

My Problem is when i create the foreign key in "Navicat" -it gives me this error.

1452-cannot add or update child row: a foreign key constraint fails....

Can any body help me - why am i getting this error - and how to fix it --

Is anything wrong --- I am trying since 2 days - no one knows how to fix it ?

Thanks,
Harsh (INDIA)
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Jun 18 '07

re: Mysql Using Navicat (error --- Foreign Key Fails)


Quote:

Originally Posted by Harshpandya

Hi I am new at ASP and MYSQL.

I am Using Navicat to access MYSQL database.

My Problem is when i create the foreign key in "Navicat" -it gives me this error.

1452-cannot add or update child row: a foreign key constraint fails....

Can any body help me - why am i getting this error - and how to fix it --

Is anything wrong --- I am trying since 2 days - no one knows how to fix it ?

Thanks,
Harsh (INDIA)

Apparently a foreign key constraint has failed. You can use

Expand|Select|Wrap|Line Numbers
  1. show innodb status; 
to show the last foreign key constraint that failed.
Newbie
 
Join Date: Jun 2007
Posts: 29
#3: Jun 18 '07

re: Mysql Using Navicat (error --- Foreign Key Fails)


Quote:

Originally Posted by r035198x

Apparently a foreign key constraint has failed. You can use

Expand|Select|Wrap|Line Numbers
  1. show innodb status; 
to show the last foreign key constraint that failed.

I am sorry but i did not get it. I am using Navicat that is only GUI no code section.

Details: I want to do relationships with two tables. Players and Manufacturers

To do that in VWD. i have to assign the index key and foreign key in Navicat.

When i put the Index key it works but when i assign foreign key -- it ask me to put the reference table and choose the columns i want.

I choose - what i want and when i click ok i get this error that

Foreign Key constraint Fails:------


Thanks in advance,
Harsh
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Jun 18 '07

re: Mysql Using Navicat (error --- Foreign Key Fails)


Quote:

Originally Posted by Harshpandya

I am sorry but i did not get it. I am using Navicat that is only GUI no code section.

Details: I want to do relationships with two tables. Players and Manufacturers

To do that in VWD. i have to assign the index key and foreign key in Navicat.

When i put the Index key it works but when i assign foreign key -- it ask me to put the reference table and choose the columns i want.

I choose - what i want and when i click ok i get this error that

Foreign Key constraint Fails:------


Thanks in advance,
Harsh

Well you have to understand your tables and the constraints that exist on them. Something is happening to a foreign key which is not allowed by one of your constraints. Check against your constratints.
Newbie
 
Join Date: Sep 2009
Posts: 1
#5: Sep 9 '09

re: Mysql Using Navicat (error --- Foreign Key Fails)


i meet the same error. I found my mistake is I inserted data, which not corresponding to both table before I create foreign key.

Ex: table a(id, name) with 2 record (1,peter); (2, flower)
table b(id, sex) with 3 record (1, male); (2, female); (3, male)
so when create foreign key for id of table b -> id of table a, record 3 of table b can't find any record of table a correspond.
Reply