Database PostgreSQL错误:关系已存在-创建表中存在外键
我正在做一张桌子如下:Database PostgreSQL错误:关系已存在-创建表中存在外键,database,postgresql,indexing,namespaces,Database,Postgresql,Indexing,Namespaces,我正在做一张桌子如下: CREATE TABLE creator.lists ( _id bigserial PRIMARY KEY NOT NULL, account_id bigint NOT NULL, created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, display_name text DEFAULT '', name text DEFAULT '', extra jsonb,
CREATE TABLE creator.lists
(
_id bigserial PRIMARY KEY NOT NULL,
account_id bigint NOT NULL,
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
display_name text DEFAULT '',
name text DEFAULT '',
extra jsonb,
FOREIGN KEY (account_id)
REFERENCES creator.accounts (_id)
ON DELETE CASCADE
);
但我得到了这个错误:
ERROR: relation "account_id_index" already exists
当我跑步时:
CREATE INDEX
account_id_index
ON
creator.lists
(
account_id
);
如何在外键上创建索引?我正在运行v11.1
请注意,我以前也为另一个表运行过类似的命令:
CREATE INDEX
account_id_index
ON
creator.contacts
(
account_id
);
我不认为表之间的索引名必须是唯一的?好的,似乎在删除命名时索引名必须是唯一的:
CREATE INDEX
ON
creator.contacts
(
account_id
);
从:
好的,似乎在删除命名时索引名需要唯一:
CREATE INDEX
ON
creator.contacts
(
account_id
);
从:
索引与表、视图和序列位于同一名称空间中,因此在一个模式中,不能对这些对象使用同一名称两次 请选择其他名称,或让PostgreSQL为您选择一个名称:
CREATE INDEX ON creator.lists (account_id);
索引与表、视图和序列位于同一名称空间中,因此在一个模式中,不能对这些对象使用同一名称两次 请选择其他名称,或让PostgreSQL为您选择一个名称:
CREATE INDEX ON creator.lists (account_id);
我决定让psql为我做:)我决定让psql为我做:)