Re: #1452 - Cannot add or update a child row: a foreign key constraint fails?
Posted by: Walter Stingl
Date: October 25, 2010 02:56AM

Hi folks,

i use MySQL 5.1.35-community-log vie TCP/IP and I'm stuck with the following FOREIGN KEY problem:


CREATE TABLE record (
pk1 TIMESTAMP NOT NULL,
pk2 CHAR(23) NOT NULL,
PRIMARY KEY (pk1,pk2),
sessionId VARCHAR(124) NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE client (
pk3 TIMESTAMP NOT NULL,
pk4 CHAR(23) NOT NULL,
PRIMARY KEY (pk3,pk4),
FOREIGN KEY (pk3,pk4) references record (pk1,pk2) on delete CASCADE on update CASCADE,
clientName VARCHAR(63)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into record (pk1,pk2,sessionid) values('2010-10-01
08:10:00', 'abcdef','hghghjghjkgh');

insert into client (pk3,pk4,clientName) values('2010-10-01 08:10:00', 'abcdef','gero');

select * from record; (This record exists !!!)
select * from client; (This record exists !!!)

update client set clientName = 'Walter' where clientName = 'gero';

Cannot add or update a child row: a foreign key constraint fails (`kojacfk`.`client`, CONSTRAINT `client_ibfk_1` FOREIGN KEY (`pk3`, `pk4`) REFERENCES `record` (`pk1`, `pk2`) ON DELETE CASCADE ON UPDATE CASCADE)

Any help is appreciated.

Options: ReplyQuote


Subject
Written By
Posted
Re: #1452 - Cannot add or update a child row: a foreign key constraint fails?
October 25, 2010 02:56AM


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.