Heroku rake db:migrate does not create tables (Rails 5)

浪尽此生 提交于 2019-12-20 05:41:40

问题


I have a Rails 5 app and I wanted to destroy and rebuild my live database (site not launched yet). So I followed the steps that should've worked (they used to work in the past):

  1. heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name}
  2. heroku run rake db:migrate
  3. heroku run rake db:seed

Steps 1 & 2 complete successfully and step 3 fails with the error ('adminsettings' is one of my tables):

Running rake db:seed on {app_name}... starting, run.7198 (Hobby)
Running rake db:seed on {app_name}... connecting, run.7198 (Hobby)
Running rake db:seed on {app_name}... up, run.7198 (Hobby)
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "adminsettings" does not exist
LINE 8:                WHERE a.attrelid = '"adminsettings"'::regclas...

If I run heroku pg:info it returns I have 2 tables (I should have about 10) so it is as if the step 2 failed (even though there was no error). If I check pgAdmin4 I can only see 2 tables: ar_internal_metadata and schema_migrations which are not my custom tables.

I deleted all migrations after ensuring they are in my schema.rb file so there are actually no migrations necessary - just the table creations. So my first question is: Does (should!) the 'heroku rake db:migrate' just use the schema.rb file to build the tables?

This is a Rails 5.2.2 app but it started off as Rails 4.x app and I upgraded all gems along the way. Would this be a cause somehow? There was no issue up to now except when I tried this destructive rebuild. Otherwise, I'm out of ideas. And I don't have much debug visibility into what is going wrong.


回答1:


rake db:migrate won't load the schema.rb file. It'll only run the migrations. If you want to load the schema then you can use rake db:schema:load.

You might also need to be careful if you reinstate your migrations to run again as the schema_migrations table probably has a record of all your migrations having run already. You'd need to clear that table too (delete the records - not drop the table) in order to indicate that your migrations should run again.



来源:https://stackoverflow.com/questions/58106064/heroku-rake-dbmigrate-does-not-create-tables-rails-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!