Skip navigation links

MySQL Forums :: Newbie :: foreign key constraint fails


Advanced Search

Re: foreign key constraint fails
Posted by: Jon Erik Ween ()
Date: March 30, 2012 02:33PM

OK, is that what you need?

This works:

INSERT INTO `RHSSP`.`CmeList` (
`CeID` ,
`CeDateTime` ,
`CeEvCat` ,
`CeHours` ,
`CePresenter` ,
`CeDescript` ,
`CeLoc` ,
`CeDocName` ,
`CeDocSize` ,
`CeDocType`
)
VALUES (
NULL , '2012-03-30', '114', '2', 'jack', 'talk', 'Auditorium', NULL , NULL , NULL
);


This doesn't:

INSERT INTO `RHSSP`.`CmeList` (

`CeID` ,
`CeDateTime` ,
`CeEvCat` ,
`CeHours` ,
`CePresenter` ,
`CeDescript` ,
`CeLoc` ,
`CeDocName` ,
`CeDocSize` ,
`CeDocType`
)
VALUES (
NULL , '2012-03-30', '115', '2', 'jack', 'talk', 'Auditorium', NULL , NULL , NULL
)
MySQL said:

#1452 - Cannot add or update a child row: a foreign key constraint fails (`rhssp`.`cmelist`, CONSTRAINT `cmelist_ibfk_1` FOREIGN KEY (`CeEvCat`) REFERENCES `lookup` (`LuID`))


As long as CeEvCat (constrained to Lookup.LuID) is <115 we get the first behavior. Anything above 115 we fail. Here are the table structures:

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 NOT NULL,
CeEvCat INT UNSIGNED NOT NULL,
CeHours DECIMAL(3,2) UNSIGNED NOT NULL,
CePresenter TEXT NOT NULL,
CeDescription TEXT NOT NULL,
CeLoc TEXT NOT NULL,
CeDoc BLOB,
INDEX (CeEvCat, CeID),
FOREIGN KEY (CeEvCat) REFERENCES Lookup(LuID)
) ENGINE=InnoDB;

Thanks for helping!

Jon

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.