2
# Bug#21704: Renaming column does not update FK definition.
5
# Test that it's not possible to rename columns participating in a
6
# foreign key (either in the referencing or referenced table).
8
DROP TABLE IF EXISTS t1;
9
DROP TABLE IF EXISTS t2;
10
DROP TABLE IF EXISTS t3;
11
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ROW_FORMAT=COMPACT ENGINE=INNODB;
12
CREATE TABLE t2 (a INT PRIMARY KEY, b INT,
13
CONSTRAINT fk1 FOREIGN KEY (a) REFERENCES t1(a))
14
ROW_FORMAT=COMPACT ENGINE=INNODB;
15
CREATE TABLE t3 (a INT PRIMARY KEY, b INT, KEY(b), C INT,
16
CONSTRAINT fk2 FOREIGN KEY (b) REFERENCES t3 (a))
17
ROW_FORMAT=COMPACT ENGINE=INNODB;
18
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
19
INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
20
INSERT INTO t3 VALUES (1,1,1),(2,2,2),(3,3,3);
22
# Test renaming the column in the referenced table.
24
ALTER TABLE t1 CHANGE a c INT;
25
ERROR HY000: Error on rename of '#sql-temporary' to './test/t1' (errno: 150)
26
# Ensure that online column rename works.
27
ALTER TABLE t1 CHANGE b c INT;
29
info: Records: 0 Duplicates: 0 Warnings: 0
31
# Test renaming the column in the referencing table
33
ALTER TABLE t2 CHANGE a c INT;
34
ERROR HY000: Error on rename of '#sql-temporary' to './test/t2' (errno: 150)
35
# Ensure that online column rename works.
36
ALTER TABLE t2 CHANGE b c INT;
38
info: Records: 0 Duplicates: 0 Warnings: 0
40
# Test with self-referential constraints
42
ALTER TABLE t3 CHANGE a d INT;
43
ERROR HY000: Error on rename of '#sql-temporary' to './test/t3' (errno: 150)
44
ALTER TABLE t3 CHANGE b d INT;
45
ERROR HY000: Error on rename of '#sql-temporary' to './test/t3' (errno: 150)
46
# Ensure that online column rename works.
47
ALTER TABLE t3 CHANGE c d INT;
49
info: Records: 0 Duplicates: 0 Warnings: 0