Heroku rake db:migrate does not create tables (Rai

2020-05-08 01:39发布

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条回答
萌系小妹纸
2楼-- · 2020-05-08 02:16

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.

查看更多
登录 后发表回答