加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – psql错误:关系已经存在

发布时间:2020-12-17 03:47:31 所属栏目:百科 来源:网络整理
导读:我正在使用postgres编写一个rails项目,服务器中有一些数据.我想把数据从远端转储到本地,所以我写脚本来做,但是出现了一些错误. 这是转储脚本: run "PGPASSWORD='#{remote_settings['password']}' pg_dump -U #{remote_settings["username"]} #{"-h '#{remot
我正在使用postgres编写一个rails项目,服务器中有一些数据.我想把数据从远端转储到本地,所以我写脚本来做,但是出现了一些错误.

这是转储脚本:

run "PGPASSWORD='#{remote_settings['password']}' 
pg_dump -U #{remote_settings["username"]} #{"-h '#{remote_settings["host"]}'" 
if remote_settings["host"]} 
'#{remote_settings["database"]}' > #{remote_sql_file_path}"

有一些代码要运输..

Transport codes

这是恢复脚本:

run_locally "PGPASSWORD='#{local_settings['password']}' psql -U 
#{local_settings["username"]} -d #{local_settings["database"]} 
-f #{local_sql_file_path}"

我成功获取了数据文件,但是当运行** restore脚本时出现了一些错误*:

psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:46: ERROR:  relation        "refinery_images" already exists
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:49: ERROR:  role "ib5k" does not exist
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:60: ERROR:  relation "refinery_images_id_seq" already exists
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:63: ERROR:  role "ib5k" does not exist
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:83: ERROR:  relation "refinery_page_part_translations" already exists
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:86: ERROR:  role "ib5k" does not exist
...
sql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:525: ERROR:  duplicate key  value violates unique constraint "refinery_images_pkey"
DETAIL:  Key (id)=(1) already exists.
CONTEXT:  COPY refinery_images,line 2: ""
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:547: ERROR:  duplicate key value violates unique constraint "refinery_page_part_translations_pkey"
DETAIL:  Key (id)=(1) already exists.
CONTEXT:  COPY refinery_page_part_translations,line 8: ""
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:569: ERROR:  duplicate key value violates unique constraint "refinery_page_parts_pkey"
DETAIL:  Key (id)=(1) already exists.
CONTEXT:  COPY refinery_page_parts,line 8: ""
...

并且本地的数据库不会更新.
我想知道如何解决它?添加一些参数?先感谢您.

解决方法

您可以将-c或–clean参数用于 pg_dump.该参数将在运行命令之前删除现有数据库对象以创建它们.

另一种方法是在恢复之前自己删除这些对象. (可能使用drop schema或drop database.)

谨慎使用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读