162: ERROR: duplicate key value violates unique constraint "articles_pkey" when I try to run the command: psql newsdata.sql

162: ERROR: duplicate key value violates unique constraint "articles_pkey" when I try to run the command: psql newsdata.sql

我在 运行 以下

尝试连接我的数据库时得到了这个
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

我只是不明白什么是复制密钥,所以我可以修复它,我是初学者,你能提供一个详细的答案吗?哪怕只是一个link检查一下,也会有很大的帮助。

详细信息:密钥 (id)=(23) 已存在。 详细信息:密钥 (id)=(1) 已存在。

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

因此违反了唯一约束,每个元组都没有唯一 ID。

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

的 table