162:错误:当我尝试运行命令:psql newsdata时,重复的键值违反了唯一约束"articles_pkey".sql



我在运行以下

时尝试连接DB时会得到这个
psql newsdata.sql

这是整个输出

vagrant@vagrant:/vagrant$ psql -d news -f newsdata.sql
SET
SET
SET
SET
SET
SET
SET
SET
SET
psql:newsdata.sql:31: ERROR:  relation "articles" already exists
ALTER TABLE
psql:newsdata.sql:45: ERROR:  relation "articles_id_seq" already exists
ALTER TABLE
ALTER SEQUENCE
psql:newsdata.sql:65: ERROR:  relation "authors" already exists
ALTER TABLE
psql:newsdata.sql:79: ERROR:  relation "authors_id_seq" already exists
ALTER TABLE
ALTER SEQUENCE
psql:newsdata.sql:102: ERROR:  relation "log" already exists
ALTER TABLE
psql:newsdata.sql:116: ERROR:  relation "log_id_seq" already exists
ALTER TABLE
ALTER SEQUENCE
ALTER TABLE
ALTER TABLE
ALTER TABLE
psql:newsdata.sql:162: ERROR:  duplicate key value violates unique constraint "articles_pkey"
DETAIL:  Key (id)=(23) already exists.
CONTEXT:  COPY articles, line 1
 setval
--------
     30
(1 row)
psql:newsdata.sql:181: ERROR:  duplicate key value violates unique constraint "authors_pkey"
DETAIL:  Key (id)=(1) already exists.
CONTEXT:  COPY authors, line 1
 setval
--------
      4
(1 row)
psql:newsdata.sql:1677931: ERROR:  duplicate key value violates unique constraint "log_pkey"
DETAIL:  Key (id)=(1678923) already exists.
CONTEXT:  COPY log, line 1
 setval
---------
 3356657
(1 row)
psql:newsdata.sql:1677946: ERROR:  multiple primary keys for table "articles" are not allowed
psql:newsdata.sql:1677954: ERROR:  relation "articles_slug_key" already exists
psql:newsdata.sql:1677962: ERROR:  multiple primary keys for table "authors" are not allowed
psql:newsdata.sql:1677970: ERROR:  multiple primary keys for table "log" are not allowed
psql:newsdata.sql:1677978: ERROR:  constraint "articles_author_fkey" for relation "articles" already exists

我只是不明白什么是最典范的键,所以我可以修复它,我可以为此提供详细的答案吗?即使这只是检查的链接,它也会有所帮助。

详细信息:键(id)=(23)已经存在。详细信息:键(id)=(1)已经存在。

脚本试图插入ID = 23或id = 1,但这些值已经在表中。

如此独特的约束,每个元组都没有唯一的ID。

已解决。问题是因为我之前运行了此命令,所以现在我尝试了psql -d news并起作用。输出显示了一张关系表

最新更新