If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Null Foreign Key should be Allowed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-10, 11:48
wow wow is offline
Registered User
 
Join Date: Nov 2006
Posts: 3
Null Foreign Key should be Allowed

Hi there,

City column is defined as
CITY CHAR(8),

But when it's inserted with a null value, the following error is occured:

Cannot add or update a child row: a foreign key constraint fails (`retail`.`sells`, CONSTRAINT `sells_ibfk_1` FOREIGN KEY (`CITY`) REFERENCES `cities` (`CITY_ID`))

The foreign key is defined as:

FOREIGN KEY(CITY) REFERENCES retail.CITIES(CITY_ID),

What's the problem and how is it fixed?

Thanks,
Reply With Quote
  #2 (permalink)  
Old 08-11-10, 12:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
please run this query and show the results --
Code:
SHOW CREATE TABLE sells
then please run this query and show the results --
Code:
SHOW CREATE TABLE cities
then please show the entire INSERT statement that failed
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On