I have those two tables...
CREATE TABLE `Mail` ( `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `sender` varchar(255) NOT NULL DEFAULT '', `receiver` varchar(255) NOT NULL DEFAULT '', `text` longtext , PRIMARY KEY (`timestamp`,`sender`,`receiver`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ... and ...
CREATE TABLE `MailHeader` ( `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `sender` varchar(255) NOT NULL DEFAULT '', `receiver` varchar(255) NOT NULL DEFAULT '', `title` varchar(45) DEFAULT NULL,, `seen` int(11) DEFAULT '0', `reply` int(11) DEFAULT '0', PRIMARY KEY (`timestamp`, `sender`, `receiver`), CONSTRAINT `MailHeader_ibfk_1` FOREIGN KEY ( `timestamp`, `sender`, `receiver`) REFERENCES `Mail` (`timestamp`, `sender`, `receiver`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; When I try to UPDATE a non key column like that way:
UPDATE MailHeader SET `title` = ?, `seen` = ?, `reply` = ? WHERE `sender` = ? and `receiver` = ?; Than I always get that error:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Cannot add or update a child row: a foreign key constraint fails (
usr_web4930_1.MailHeader, CONSTRAINTMailHeader_ibfk_1FOREIGN KEY (timestamp,sender,receiver) REFERENCEStimestamp,sender,receiver)
I tried the most trivial way, with one record in both tables and used the "MySQL-Workbench" tool to change a non-key column. With exactly the same error. I realy don't get it...
...with actual code. If you haveON UPDATE CURRENT_TIMESTAMPfor thetimestampcolumn - that would be the issue.