在 Postgres 9.6 上,我有一个表,其中外键约束和唯一约束具有相同的名称(最终由于长不同的名称被静默截断为 63 个字符)。我正在尝试通过 解决此名称冲突ALTER TABLE RENAME CONSTRAINT
,但这会产生错误:
table x has multiple constraints named "y"
这听起来像是为了重命名约束,我首先需要……重命名约束。?
那么,我该怎么做呢?
(旁注:PostgreSQL 11 的发行说明有“完全强制表和域约束名称的唯一性”,暗指这种情况,我想,正如我在准备升级时发现的那样。)
重现的最小步骤:
create table t1 (id uuid primary key);
create table t2 (id uuid primary key);
alter table t1 add constraint oops foreign key (id) references t2 (id);
alter table t1 add constraint oops unique (id);
alter table t1 rename constraint oops to oopsie;