rails错误:关系已经存在

时间:2017-07-28 01:43:14

标签: ruby-on-rails postgresql docker

我试图将我的rails应用程序移动到Docker容器中进行生产,直到将生产转储装入容器的最后一步。

我已经完成了当前生产数据库的备份

pg_dump pdfcat_production > ~/pdfcat-20170728.dump

我之前曾经加载过它并且它有效,它是第二次失败;

docker-compose run -e 'RAILS_ENV=production' app rake db:drop
docker-compose run -e 'RAILS_ENV=production' app rake db:create
cat ~/pdfcat-20170727.dump | docker exec -i 79766cf70617 psql -Upostgres

我收到此错误;

ERROR:  relation "categories" already exists
ERROR:  role "pdfcat" does not exist
ERROR:  relation "categories_id_seq" already exists
ERROR:  role "pdfcat" does not exist
ALTER SEQUENCE
ERROR:  relation "clients" already exists
ERROR:  role "pdfcat" does not exist
ERROR:  relation "clients_id_seq" already exists
ERROR:  role "pdfcat" does not exist

完成所有这些错误后,我无法加载网络应用。

1 个答案:

答案 0 :(得分:0)

第二次加载会产生错误,因为数据已经加载到容器中,因此无法重新创建。这次你不需要加载数据。

对于当前情况,您可以删除容器并重新开始,这次数据加载不会出现任何错误。要删除容器,可以使用docker rm <contianer_id>,如果在停止或删除容器时出现问题,则系统重新启动会出现故障,并停止所有容器。重启docker服务也可能是一种选择。

如果要准备可以为任何系统首次加载数据的映像,可以在dockerfile中包含此数据加载过程。