Rails 4 如何忽略挂起的迁移 [英] Rails 4 how to ignore pending migrations
本文介绍了Rails 4 如何忽略挂起的迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题如下:
- 我有 db/seed.rb 的初始数据.
- 其中一次迁移取决于此种子提供的数据.
- 我正在尝试从空数据库部署我的应用.
结果是:
- RAILS_ENV=production rake db:migrate - 由于缺少初始数据而失败
- RAILS_ENV=production rake db:seed - 由于未决迁移而失败
我想以某种方式告诉 rake 忽略挂起的迁移,但目前无法做到.
I wanted to somehow tell rake to ignore pending migrations, but unable to do it so far.
更新(由于额外的经验)
有时迁移和模型代码不同步,因此不会运行迁移.为了避免这个问题,最近在迁移中使用了重新定义模型:
Sometimes migrations and model code goes out of sync, so migrations not being run. To avoid this problem recently used redefining of model in migrations:
# reset all callbacks, hooks, etc for this model
class MyAwesomeModel < ActiveRecord::Base
end
class DoSomethingCool < ActiveRecord::Migration
def change
...
end
end
推荐答案
Rails 将迁移信息存储在名为 schema_migrations
的表中.
Rails stores migration information in a table called schema_migrations
.
您可以将迁移中的版本添加到该表中以跳过特定的迁移.
You can add the version from your migration into that table to skip a specific migration.
版本是文件名中描述之前的数字字符串.
The version is the number string which comes before the description in the file name.
[version]_Create_Awesome.rb
这篇关于Rails 4 如何忽略挂起的迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文