dbTalk Databases Forums  

error 150

comp.databases.mysql comp.databases.mysql


Discuss error 150 in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Teng Tao
 
Posts: n/a

Default error 150 - 08-08-2006 , 09:26 PM






i have created 2 tables and want to make a FK between them,
ALTER TABLE `icts`.`fact_customer_feedback` ADD CONSTRAINT
`FK_fact_customer_feedback_2` FOREIGN KEY `FK_fact_customer_feedback_2`
(`CFcustomer_Id`)
REFERENCES `fact_customer` (`id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
but it ruturns the error number 1452
cannot add or update a child row : a foreign key constraint fails.

thanks



Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: error 150 - 08-08-2006 , 09:48 PM






Teng Tao wrote:
Quote:
i have created 2 tables and want to make a FK between them,
ALTER TABLE `icts`.`fact_customer_feedback` ADD CONSTRAINT
`FK_fact_customer_feedback_2` FOREIGN KEY `FK_fact_customer_feedback_2`
(`CFcustomer_Id`)
REFERENCES `fact_customer` (`id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
but it ruturns the error number 1452
cannot add or update a child row : a foreign key constraint fails.

thanks


You have (at least) a row in fact_customer_feedback.CFcustomer_Id which
does not exist in fact_customer.id.

When you create any constraint (not just a foreign key), all rows in the
table must satisfy the constraint or the creation will fail.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================


Reply With Quote
  #3  
Old   
Bill Karwin
 
Posts: n/a

Default Re: error 150 - 08-09-2006 , 02:03 AM



Teng Tao wrote:
Quote:
i have created 2 tables and want to make a FK between them,
ALTER TABLE `icts`.`fact_customer_feedback` ADD CONSTRAINT
`FK_fact_customer_feedback_2` FOREIGN KEY `FK_fact_customer_feedback_2`
(`CFcustomer_Id`)
REFERENCES `fact_customer` (`id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
but it ruturns the error number 1452
cannot add or update a child row : a foreign key constraint fails.
In addition to Jerry's advice, it is also common that one gets this
error because the referencing and referenced columns aren't of
compatible datatypes.

Read the conditions for creating a foreign key on this doc page:
http://dev.mysql.com/doc/refman/5.0/...nstraints.html

Regards,
Bill K.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.