问题描述
我正在尝试创建一个之前已删除的表。
I am trying to create a table that was dropped previously.
但是当我执行 CREATE TABLE A ..
时。我遇到以下错误:
But when I do the CREATE TABLE A ..
. I am getting below error:
我验证了是否执行 SELECT * FROM A
,但是随后又遇到另一个错误:
I verified doing SELECT * FROM A
, but then I got another error:
我已经尝试在<$ c $中找到它c> \dS + 列出所有关系,但不存在。
为了使这一点复杂,我通过在另一个数据库中创建该表进行了测试,但得到了相同的错误。我认为删除该表时可能会出错。有任何想法吗?
I already tried to find it in \dS+
listing all relations, and it is not there.
To complicate this, I have tested this by creating this table in another database and I got the same error. I am thinking that could be an error when this table was dropped. Any ideas?
这里是代码:我使用的是Power SQL生成的代码。我没有使用序列也有同样的错误。
Here is the code: I'm using a generated code from Power SQL. I have the same error without using the sequence. It just works when I change the name and in this case I can not do that.
CREATE SEQUENCE csd_relationship_csd_relationship_id_seq;
CREATE TABLE csd_relationship (
csd_relationship_id INTEGER NOT NULL DEFAULT nextval('csd_relationship_csd_relationship_id_seq'::regclass),
type_id INTEGER NOT NULL,
object_id INTEGER NOT NULL,
CONSTRAINT csd_relationship PRIMARY KEY (csd_relationship_id)
);
推荐答案
我终于发现了错误。问题在于主键约束名称等于表名称。我不知道postgres如何表示约束,但是我认为在创建主键约束的过程中触发了错误关系已存在,因为该表已被声明。但是由于这个错误,表并没有在最后创建。
I finally discover the error. The problem is that the primary key constraint name is equal the table name. I don know how postgres represents constraints, but I think the error "Relation already exists" was being triggered during the creation of the primary key constraint because the table was already declared. But because of this error, the table wasnt created at the end.
这篇关于PostgreSQL错误:关系已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!