| 1 |
# |
| 2 |
# Bug #27453180 FOREIGN KEYS CONSTRAINTS IGNORED AFTER RENAME TABLE |
| 3 |
# |
| 4 |
SET FOREIGN_KEY_CHECKS=0; |
| 5 |
CREATE TABLE child (fk INT, FOREIGN KEY (fk) REFERENCES parent(pk)); |
| 6 |
show create table child; |
| 7 |
Table Create Table |
| 8 |
child CREATE TABLE `child` ( |
| 9 |
`fk` int DEFAULT NULL, |
| 10 |
KEY `fk` (`fk`), |
| 11 |
CONSTRAINT `child_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `parent` (`pk`) |
| 12 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 13 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_FOREIGN; |
| 14 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 15 |
test/child_ibfk_1 test/child test/parent 1 48 |
| 16 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_FOREIGN_COLS; |
| 17 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 18 |
test/child_ibfk_1 fk pk 1 |
| 19 |
INSERT INTO child VALUES (1); |
| 20 |
CREATE TABLE parent0 (pk INT PRIMARY KEY); |
| 21 |
INSERT INTO parent0 VALUES (1); |
| 22 |
RENAME TABLE parent0 TO parent; |
| 23 |
SET FOREIGN_KEY_CHECKS=1; |
| 24 |
DELETE FROM parent; |
| 25 |
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `parent` (`pk`)) |
| 26 |
DROP TABLE child; |
| 27 |
DROP TABLE parent; |
| 28 |
SET FOREIGN_KEY_CHECKS=0; |
| 29 |
CREATE TABLE child (fk INT, FOREIGN KEY (fk) REFERENCES parent(pk)); |
| 30 |
show create table child; |
| 31 |
Table Create Table |
| 32 |
child CREATE TABLE `child` ( |
| 33 |
`fk` int DEFAULT NULL, |
| 34 |
KEY `fk` (`fk`), |
| 35 |
CONSTRAINT `child_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `parent` (`pk`) |
| 36 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 37 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_FOREIGN; |
| 38 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 39 |
test/child_ibfk_1 test/child test/parent 1 48 |
| 40 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_FOREIGN_COLS; |
| 41 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 42 |
test/child_ibfk_1 fk pk 1 |
| 43 |
INSERT INTO child VALUES (1); |
| 44 |
CREATE TABLE parent0 (pk INT PRIMARY KEY); |
| 45 |
INSERT INTO parent0 VALUES (1); |
| 46 |
ALTER TABLE parent0 RENAME parent; |
| 47 |
SET FOREIGN_KEY_CHECKS=1; |
| 48 |
DELETE FROM parent; |
| 49 |
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `parent` (`pk`)) |
| 50 |
DROP TABLE child; |
| 51 |
DROP TABLE parent; |