Details
-
Bug
-
Status: Closed (View Workflow)
-
Trivial
-
Resolution: Cannot Reproduce
-
None
-
None
Description
Consider the following example. We just create two tables, second with the foreign key, and our foreign key is also a part of compound primary key of the second table:
CREATE TABLE t
|
(
|
`id` int, |
`productName` varchar(70), |
primary key (id)
|
);
|
 |
CREATE TABLE t2
|
(`id` int, `title` varchar(70), `fk_t` int, |
primary key (id, fk_t),
|
constraint `t2_to_t_fkz` foreign key (`fk_t`) references `t`(`id`));
|
|
insert into t values(1, 'product 1'); |
replace into t2(title, fk_t) values('incorrect fk, replace syntax', 9999); |
|
Last replace is an error, because the foreign key called fk_t leads to nowhere and thats why new row can't be inserted. But the server behavior varies on MySQL and MariaDB.
MySQL says:
Cannot add or update a child row: a foreign key constraint fails (`db_9_63d471`.`t2`, CONSTRAINT `t2_to_t_fkz` FOREIGN KEY (`fk_t`) REFERENCES `t` (`id`))
|
and that is correct error message.
But MariaDB says:
Error Code: 1062. Duplicate entry '0-9999' for key 'PRIMARY' |
What? Duplicate entry? But i am using REPLACE query, you should just delete a row and insert again in such a case. The error messsage is wrong and confusing.