我正在将 Rails 应用程序传输到新服务器,并且遇到错误,阻止了某些数据在具有相同数据库架构的应用程序之间传输。
如果我在两台服务器上运行 rake db:version,我会得到相同的结果。在我的新服务器上:
RAILS_ENV=production rake db:version # Returns 20181207224901
在我的旧服务器上:
heroku run rake db:version # Returns 20181207224901
我使用以下命令从旧服务器获取数据:
pg_dump --host=OMITTED_HERE_FOR_PRIVACY_SAKE --port=5432 --username=OMITTED_HERE_FOR_PRIVACY_SAKE --password --dbname=da466m517q6qf6 -t product_order_rows > pox4_product_order_rows.pg
我知道这是正确的服务器,并检查了 pg 文件的内容以确保它给了我想要的东西,我将在这篇文章中省略它,因为它有太多行。
然后我尝试将转储放在我的新数据库中,如下所示:
sudo psql -U pox4 pox4_production < pox4_product_order_rows.pg
我收到以下错误:
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
SET
ERROR: relation "product_order_rows" already exists
ERROR: role "wsgdzocxqkyzmj" does not exist
ERROR: relation "product_order_rows_id_seq" already exists
ERROR: role "wsgdzocxqkyzmj" does not exist
ALTER SEQUENCE
ALTER TABLE
ERROR: insert or update on table "product_order_rows" violates foreign key constraint "fk_rails_7fc701b8a5"
DETAIL: Key (model_id)=(17176) is not present in table "models".
setval
--------
5021
(1 row)
ERROR: multiple primary keys for table "product_order_rows" are not allowed
ERROR: relation "index_product_order_rows_on_model_id" already exists
ERROR: relation "index_product_order_rows_on_product_order_id" already exists
ERROR: constraint "fk_rails_7fc701b8a5" for relation "product_order_rows" already exists
ERROR: constraint "fk_rails_d38880b40c" for relation "product_order_rows" already exists
检查应放置数据的应用程序,我看不到任何应该传输的数据。我在其他表传输中遇到了一些错误,并且数据以某种方式进入。我不明白的是,如果它们具有相同的模式,数据甚至可能首先出现在第一个数据库中,或者为什么它会在相同的数据库中被拒绝。