Dav*_*ave 5 mysql rename constraints
create table Foo(
userId bigint(20) not null,
KEY `Foo_userId` (`userId`),
CONSTRAINT `Foo_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`)
);
Run Code Online (Sandbox Code Playgroud)
如何将键/约束名称从 Foo_userId 更改为 Bar_userId,只需更改名称即可。我知道可以先删除它们,然后重新创建它们。我正在寻找一种简单的方法,例如
alter table Foo rename KEY Foo_userId Bar_userId;
alter table Foo rename CONSTRAINT Foo_userId Bar_userId;
Run Code Online (Sandbox Code Playgroud)
mysql中有这样的东西吗?谢谢。
为了更改约束名称或属性,您可以删除旧的外键约束并添加新的外键约束。这是唯一真正对我有用的解决方案。
alter table FOO
drop foreign key Foo_userId,
add constraint Bar_userId foreign key (`userId`) references`User` (`id`)
Run Code Online (Sandbox Code Playgroud)
这是另一个对我有帮助的答案。