Skip navigation links

MySQL Forums :: Newbie :: foreign key constraint fails


Advanced Search

foreign key constraint fails
Posted by: Jon Erik Ween ()
Date: March 29, 2012 09:33AM

Hi folks

I'm not totally new to MySQL, but learning every day, like with this problem uploading records to a table from a web form with links to a lookup table for one of the field values.

The lookup table has ~200 records and is indexed on the record ID, primary key. The upload works if the Lookup table ID in the SQL is less than 115, but not when ≥115 with the following error: "1452... foreign key constraint fails". I've tried enlarging the filed size, using MyISAM engine (though I default all my tables to InnoDB), no go. Table structures and SQL below, lookup table first. (Lookup table DOES contain a unique record with ID 144):

Thanks for any suggestions

SDG

jon

CREATE TABLE Lookup (
LuID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
LuCat VARCHAR(50),
LuVal VARCHAR(50),
INDEX (LuID)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE CmeList (
CeID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
CeDateTime DATETIME,
CeEvCat INT UNSIGNED NOT NULL,
CeHours DECIMAL(3,2) UNSIGNED NOT NULL,
CeDescript TEXT,
CeDoc BLOB,
INDEX (CeEvCat, CeID),
FOREIGN KEY (CeEvCat) REFERENCES Lookup(LuID)
) ENGINE=InnoDB;

INSERT INTO CmeList (CeDateTime, CeEvCat, CeHours, CeDescript) VALUES ("12/01/2012",144,2.5,"This is a test")

Options: ReplyQuote


Subject Written By Posted
foreign key constraint fails Jon Erik Ween 03/29/2012 09:33AM
Re: foreign key constraint fails Peter Brawley 03/30/2012 10:19AM
Re: foreign key constraint fails Jon Erik Ween 03/30/2012 01:42PM
Re: foreign key constraint fails Peter Brawley 03/30/2012 11:42AM
Re: foreign key constraint fails Jon Erik Ween 03/30/2012 02:33PM
Re: foreign key constraint fails Peter Brawley 03/30/2012 07:53AM
Re: foreign key constraint fails Jon Erik Ween 03/30/2012 01:03PM
Re: foreign key constraint fails Peter Brawley 03/30/2012 08:52AM
Re: foreign key constraint fails Jon Erik Ween 03/30/2012 04:30PM
Re: foreign key constraint fails Peter Brawley 03/30/2012 09:54AM
Re: foreign key constraint fails irek kordirko 03/31/2012 12:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.