Non*_*ona 7 postgresql pg-restore postgresql-9.6
所以我有一个在 Heroku 上运行的 Rails 5.0.x 应用程序和 Postgres 9.6.1。我拉下来做一个pg_restore --exit-on-error --verbose --clean --no-acl --no-owner -h localhost -d database_development ~/Documents/Backups/myproduction.dump
我收到以下错误:
pg_restore: connecting to database for restore
pg_restore: dropping FK CONSTRAINT trial_versions fk_rails_f888baa05c
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3091; 2606 16768 FK CONSTRAINT trial_versions fk_rails_f888baa05c u7dok58iar41mh
pg_restore: [archiver (db)] could not execute query: ERROR: constraint "fk_rails_f888baa05c" of relation "trial_versions" does not exist
Command was: ALTER TABLE ONLY "public"."trial_versions" DROP CONSTRAINT "fk_rails_f888baa05c";
Run Code Online (Sandbox Code Playgroud)
这个错误告诉我什么?我以前从未遇到过这个问题。这最近才开始发生,我需要先了解错误,然后才能开始对其进行故障排除。
获取转储文件的数据库定义了某个外键约束。但是您的目标数据库没有。可能是因为自上次转储以来有人将其添加到转储的数据库中。由于您指定了--clean,它会尝试在重新创建转储文件中的所有对象之前从目标数据库中删除它们。它失败了,因为它不存在于要删除的目标数据库中。
您可以添加--if-exists到恢复命令中。或者您可以--exit-on-error从命令中删除,并忽略您收到的错误消息。