Heroku rake db:migrate不创建表(Rails 5) [英] Heroku rake db:migrate does not create tables (Rails 5)

查看:119
本文介绍了Heroku rake db:migrate不创建表(Rails 5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails 5应用程序,我想销毁并重建我的实时数据库(该网站尚未启动). 因此,我遵循了应该执行的步骤(过去曾经使用过):

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:重置HEROKU_POSTGRESQL_HEROKUCOLOR_URL-确认 {app_name}
  2. heroku运行rake db:migrate
  3. heroku运行rake db:seed
  1. heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name}
  2. heroku run rake db:migrate
  3. heroku run rake db:seed

步骤1& 2成功完成,第3步失败,并显示以下错误("adminsettings"是我的表格之一):

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...

如果我运行heroku pg:info,它将返回我有2个表(我应该有10个表),因此好像步骤2失败了(即使没有错误). 如果我检查pgAdmin4,则只能看到2个表:ar_internal_metadata和schema_migrations,它们不是我的自定义表.

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.

在确保所有迁移在我的schema.rb文件中之后,我删除了所有迁移,因此实际上没有必要进行迁移-仅创建表即可.所以我的第一个问题是:(应该!)"heroku rake db:migrate"是否仅使用schema.rb文件来构建表?

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?

这是一个Rails 5.2.2应用程序,但是从Rails 4.x应用程序开始,我一路升级了所有的gem.这会是某种原因吗?到目前为止,除了我尝试进行此破坏性重建时,没有其他问题. 否则,我就没主意了.而且我对发生的问题没有太多的调试可见性.

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.

推荐答案

rake db:migrate不会加载schema.rb文件.它只会运行迁移.如果要加载架构,则可以使用rake db:schema:load.

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.

如果您恢复迁移以再次运行,则可能还需要小心,因为schema_migrations表可能记录了所有已运行的迁移.您还需要清除该表(删除记录-不要删除表),以指示您的迁移应再次运行.

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.

这篇关于Heroku rake db:migrate不创建表(Rails 5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆