Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Posts
    3

    Unanswered: 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,

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •