我在运行以下命令时尝试连接数据库时得到了
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
我只是不明白什么是双重密钥,所以我可以修复它,请您为这个问题提供详细的答案?即使只是检查链接,也会有很大帮助。
答案 0 :(得分:0)
详细信息:密钥(id)=(23)已经存在。 详细信息:密钥(id)=(1)已经存在。
脚本试图插入id = 23或id = 1,但这些值已在表中。
因此违反了唯一约束,并且每个元组都没有唯一的ID。
答案 1 :(得分:0)
解决了。
问题是因为我之前运行过此命令,所以现在我尝试了psql -d news
并成功了。
输出显示关系表