Note that there are some explanatory texts on larger screens.

plurals
  1. POrails migration runs on local Postgresql but fails on prod
    text
    copied!<p>In short, dropping, creating, and running migrate on the local Postgres instance will work any number of times for creating a working database for my app, but the same technique on Heroku's prod always produces:</p> <pre><code>heroku run rake db:migrate Running `rake db:migrate` attached to terminal... up, run.9674 PG::UndefinedTable: ERROR: relation "mytable" does not exist LINE 5: WHERE a.attrelid = '"mytable"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"mytable"'::regclass AND a.attnum &gt; 0 AND NOT a.attisdropped ORDER BY a.attnum rake aborted! PG::UndefinedTable: ERROR: relation "mytable" does not exist LINE 5: WHERE a.attrelid = '"mytable"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"mytable"'::regclass AND a.attnum &gt; 0 AND NOT a.attisdropped ORDER BY a.attnum </code></pre> <p>EDIT: see bottom of question for clue on controller getting accessed during migrate.</p> <p>This is what works locally:</p> <pre><code>rake db:drop rake db:create rake db:migrate </code></pre> <p>I have </p> <ul> <li>confirmed that Heroku's db is blank before migration by doing <code>heroku pg:psql</code> and then <code>\dt</code> to verify 0 tables exist.</li> <li>tried <code>heroku pg:reset DATABASE</code> before the migrate</li> <li>confirmed both local and prod Postgres is version 9.2.4</li> <li>tried renaming the "mytable" migration file in <code>db/migrate</code> to have the earliest timestamp so as to get run first</li> </ul> <p>This is a pretty simple app so it's very frustrating that something basic like creating a db from scratch keeps failing. Any ideas?</p> <p>"mytable" migration:</p> <pre><code>class CreateMytable &lt; ActiveRecord::Migration def change create_table :mytable do |t| t.string :codes t.string :name t.timestamps end end end </code></pre> <p>likely referecing migration:</p> <pre><code>class CreateTable2 &lt; ActiveRecord::Migration def change create_table :table2 do |t| t.references :a, index: true t.references :b, index: true t.string :c t.string :d t.timestamps end end end </code></pre> <p>EDIT: noticed a clue when running db:migrate with --trace. The top of the stack trace below error shows a controller error?? Why is a controller getting involved with a migration?</p> <pre><code>/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_no_cache' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `block in exec_query' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log' /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:915:in `column_definitions' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:174:in `columns' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:208:in `columns' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:242:in `column_defaults' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/locking/optimistic.rb:169:in `column_defaults' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/core.rb:181:in `initialize' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new' /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new' /app/app/controllers/home_controller.rb:7:in `&lt;class:HomeController&gt;' </code></pre> <p>The line 7 in question contains a call to <code>Mytable.new(...</code> . How is it controller code is coming into scope during a db:migrate?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload