Heroku 运行 rake db:migrate 导致数据库没有变化,应用程序重新启动了几次 [英] Heroku run rake db:migrate results in no change in the database, app restarted several times

查看:19
本文介绍了Heroku 运行 rake db:migrate 导致数据库没有变化,应用程序重新启动了几次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将迁移推送到生产数据库时遇到问题.

I have a problem with pushing my migrations to the production database.

问题:

  1. 我通过添加 1 列更改了数据库架构.
  2. 我已将其迁移到生产数据库:

  1. I've altered database schema by adding 1 column.
  2. I've migrated it to the production database:

MacBook-Air-Mac:app msc$ rake db:migrate RAILS_ENV="生产"[RailsAdmin] 默认情况下禁用 RailsAdmin 初始化.如果需要,请传递 SKIP_RAILS_ADMIN_INITIALIZER=false .== AddLengthColumnToBooks:迁移 ==========================================-- add_column(:books, :length, :integer)-> 0.0017s== AddLengthColumnToBooks:迁移(0.0019s)================================

MacBook-Air-Mac:app msc$ rake db:migrate RAILS_ENV="production" [RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it. == AddLengthColumnToBooks: migrating ========================================= -- add_column(:books, :length, :integer) -> 0.0017s == AddLengthColumnToBooks: migrated (0.0019s) ================================

考虑到新的 DB 模式现已投入生产,我已经部署了使用 :length 执行某些操作的代码.

Thinking that the new DB schema is now in production, I've deployed the code which does some things with :length.

在生产中,我收到以下错误:

In production, I got the following error:

未定义的方法`length=' for #

undefined method `length=' for #

我执行了 heroku 回滚 并将应用程序降级到最新的可靠版本.

I did heroku rollback and downgraded the app to the latest reliable version.

然后(可能有点晚了)我发现我必须heroku restart 应用程序来加载新索引.我做了好几次.

THEN (a bit too late probably) I found out that I have to heroku restart the app to load the new indexes. I did this several times.

然后我打开控制台并检查了Book.column_names,但是没有length

I opened the console then and checked Book.column_names, but there was no length

我又做了一次 heroku run rake db:migrate 之后是 heroku restart,没有任何变化.

I did heroku run rake db:migrate followed by heroku restart one more time, no change.

我尝试将另一列迁移到生产数据库,但根本没有收到任何消息,甚至没有收到第 2 页的消息.

I've tried migrating another column to the production db, but didn't get any message at all, not even the one from p.2.

我在这里做错了什么?

更新

根据 Philipe 的回答,我做了一些额外的步骤:

Based on the answers of Philipe, I did a number of additional steps:

  1. git add db/schema.rb, git add db/migrate/20130325103953_add_length_column_to_books.rb 和git add db/migrate/20130401041910_add_duration_column_to_books.rb".Git 的回答是:
  2. 要提交的更改:(使用git reset HEAD ..."取消暂存)

  1. git add db/schema.rb, git add db/migrate/20130325103953_add_length_column_to_books.rb and 'git add db/migrate/20130401041910_add_duration_column_to_books.rb'. Git's answer was:
  2. Changes to be committed: (use "git reset HEAD ..." to unstage)

新文件:db/migrate/20130325103953_add_length_column_to_books.rb新文件:db/migrate/20130401041910_add_duration_column_to_books.rb修改:db/schema.rb

new file: db/migrate/20130325103953_add_length_column_to_books.rb new file: db/migrate/20130401041910_add_duration_column_to_books.rb modified: db/schema.rb

然后我做了git commit -m更新架构".

同样的输出是:

 3 files changed, 168 insertions(+), 156 deletions(-)

创建模式 100644 db/migrate/20130325103953_add_length_column_to_books.rb创建模式 100644 db/migrate/20130401041910_add_duration_column_to_books.rb

create mode 100644 db/migrate/20130325103953_add_length_column_to_books.rb create mode 100644 db/migrate/20130401041910_add_duration_column_to_books.rb

然后我运行 heroku run rake db:migrate.不幸的是,没有迁移的迹象,只是得到了:

Then I run heroku run rake db:migrate. Unfortunately there was no sign of migrations, simply got:

运行 rake db:migrate 附加到终端... up, run.5428就是这样.

Running rake db:migrate attached to terminal... up, run.5428 and that's it.

在生产的 Rails 控制台中,运行 Book.column_names 仍然缺乏长度和持续时间.

In the production Rails Console, running Book.column_names still lacks both length and duration.

现在我更没有想法了.`

Now I'm even more out of ideas. `

推荐答案

您似乎没有将更改推送到 Heroku.步骤应该如下;

It doesn't look like you are pushing changes to Heroku. Steps should be as follows;

  1. 更改本地代码
  2. 在本地运行任何迁移
  3. 将所有更改的文件添加到 Git git add .
  4. 提交所有添加的文件到 git git commit -m "Adding features"
  5. 将更改推送到 Heroku git push heroku master - 假设您使用 heroku 作为远程名称并且您正在使用 master分支
  6. 如果您有迁移,请运行 heroku run rake db:migrate 以在 HEROKU 上运行迁移
  7. 以下迁移执行 heroku restart
  1. Make changes to local code
  2. Run any migrations LOCALLY
  3. Add all changed files to Git git add .
  4. Commit all added files to git git commit -m "Adding features"
  5. Push the changes to Heroku git push heroku master - assuming you are using heroku as your remote name and you are working in the master branch
  6. If you have migrations run heroku run rake db:migrate to run the migrations ON HEROKU
  7. Following migrations do heroku restart

这应该是您工作所需的全部.

That should be all you need to get you working.

这篇关于Heroku 运行 rake db:migrate 导致数据库没有变化,应用程序重新启动了几次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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