forums › forums › SQLyog › SQLyog: Bugs / Feature Requests › Cannot Create Pk/relationship In Mysql
- This topic is empty.
-
AuthorPosts
-
-
January 20, 2007 at 3:57 pm #10141deux_ex_machinaMember
Hi,
When I tried to create PK/Relationship using SQLyog I always get the error 1216 “Cannot Add or Update a Child row: foreign key constraint fails”.
Thanks,
Deux
-
January 22, 2007 at 5:34 am #23277peterlaursenParticipant
This is sprobably because the tables contain data. And the FK you define are conflicting with the data!
example:
If 'child' (table `orders') has a column CustomerId pointing to the ID column of 'parent' (table `customers`) and if `customers`.`ID` holds the data '1','2','3' and '4' you cannot define a PK if `orders`.`CustomerId` hold other data than '1','2','3' and '4'.
A Foreing Key is a CONSTRAINT on data. there can only be data in 'child' that are in 'parent' too.
You could try starting with empty tables!
-
January 22, 2007 at 9:14 am #23278deux_ex_machinaMemberpeterlaursen wrote on Jan 21 2007, 09:34 PM:This is sprobably because the tables contain data. And the FK you define are conflicting with the data!
example:
If 'child' (table `orders') has a column CustomerId pointing to the ID column of 'parent' (table `customers`) and if `customers`.`ID` holds the data '1','2','3' and '4' you cannot define a PK if `orders`.`CustomerId` hold other data than '1','2','3' and '4'.
A Foreing Key is a CONSTRAINT on data. there can only be data in 'child' that are in 'parent' too.
You could try starting with empty tables!
Hi Pete,
Thanks for the reply I tried what you have said, I even tried having the fields Null and Not Null “all fields are empty” but still I'm getting this problems.
Deauxii
-
January 22, 2007 at 10:45 am #23279peterlaursenParticipant
let us se a structure-only dump for the tables and the SQL (from history) what you are trying to do and/or a screendump.
-
-
AuthorPosts
- You must be logged in to reply to this topic.