title: PSQL database transfer and errors
body: <p>I'm transferring a rails app to a new server, and have run into errors preventing some data from being transferred between apps with identical db schema.</p>
  
  <p>If I run rake db:version on both servers, I get the same result. On my new server:</p>
  
  <pre><code>RAILS_ENV=production rake db:version # Returns 20181207224901
  </code></pre>
  
  <p>On my old server:</p>
  
  <pre><code>heroku run rake db:version # Returns 20181207224901
  </code></pre>
  
  <p>I got the data from the old server with the following command:</p>
  
  <pre><code>pg_dump --host=OMITTED_HERE_FOR_PRIVACY_SAKE --port=5432 --username=OMITTED_HERE_FOR_PRIVACY_SAKE --password --dbname=da466m517q6qf6 -t product_order_rows &gt; pox4_product_order_rows.pg
  </code></pre>
  
  <p>I know this is the correct server, and have checked the contents of the pg file to make sure it gave me what I wanted, which I will omit from this post because it has too many rows.</p>
  
  <p>I then try to place the dump in my new database like so:</p>
  
  <pre><code>sudo psql -U pox4 pox4_production &lt; pox4_product_order_rows.pg
  </code></pre>
  
  <p>And I get the following errors:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Checking the app where the data should be placed, I see none of the data that's suppose to be transferred over. I've gotten some of these errors on other table transfers, and the data somehow made it in. What I don't understand is how the data could even be in the first database in the first place if they have the same schema, or why it would be rejected in an identical database.</p>