Skip to content

Foreign key is not updated when changing column name and type #59705

@pcqz

Description

@pcqz

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

set foreign_key_checks=off;
create table child (id int,pid_test int,foreign key (pid_test) references parent(pid));
alter table child change column pid_test pid varchar(10);

2. What did you expect to see? (Required)

The foreign key is updated from pid_test to pid.

3. What did you see instead (Required)

mysql> show create table child;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                            |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| child | CREATE TABLE `child` (
  `id` int(11) DEFAULT NULL,
  `pid` varchar(10) DEFAULT NULL,
  KEY `fk_1` (`pid`),
  CONSTRAINT `fk_1` FOREIGN KEY (`pid_test`) REFERENCES `test`.`parent` (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from information_schema.key_column_usage;
ERROR 1105 (HY000): runtime error: invalid memory address or nil pointer dereference

4. What is your TiDB version? (Required)

v6.5.6 and above

Metadata

Metadata

Assignees

Labels

affects-8.5This bug affects the 8.5.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.impact/panicreport/customerCustomers have encountered this bug.severity/majortype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions