Last active
July 4, 2021 04:38
-
-
Save myl7/993da0817dcba74eeb19d41e950c9a26 to your computer and use it in GitHub Desktop.
Reproduce the bug that inline foreign key in create table is ignored by MySQL: https://bugs.mysql.com/bug.php?id=17943 & https://stackoverflow.com/a/60103054/11691878
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- $ mysql --version | |
-- mysql Ver 8.0.24 for Linux on x86_64 (Source distribution) | |
create table a(id int primary key); | |
-- Query OK, 0 rows affected (0.03 sec) | |
create table b(id int primary key, fk int references a(id)); | |
-- Query OK, 0 rows affected (0.05 sec) | |
insert into b values (1, 2); | |
-- Query OK, 1 row affected (0.00 sec) | |
create table c(id int primary key, fk int, foreign key (fk) references a(id)); | |
-- Query OK, 0 rows affected (0.02 sec) | |
insert into c values (1, 2); | |
-- ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`c`, CONSTRAINT `c_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `a` (`id`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment