耙分贝:迁移没有检测到新的迁移? [英] rake db:migrate doesn't detect new migration?

查看:115
本文介绍了耙分贝:迁移没有检测到新的迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经验和Rails / ActiveRecord的2.1.1

Experienced with Rails / ActiveRecord 2.1.1

  • 您创建第一个版本(例如)Ruby脚本\生成支架产品名称:字符串描述:文字图片网址:字符串
  • 在此创建(例如)迁移文件名为20080910122415_create_products.rb
  • 您应用迁移与耙分贝:迁移
  • 现在,你添加一个字段与Ruby脚本的产品表\产生迁移add_price_to_product价格:十进制
  • 在此创建一个名为20080910125745_add_price_to_product.rb迁移文件
  • 如果您尝试运行耙分贝:迁移,它实际上将恢复第一个迁移,不适用于下一个!所以,你的产品表将被摧毁!
  • 但是,如果你独自跑耙,它会告诉你,一个移民正等待

请注意,将耙分贝:迁移(一旦表已被破坏)将适用于所有迁移,以

Pls note that applying rake db:migrate (once the table has been destroyed) will apply all migrations in order.

我发现的唯一的解决方法是指定新移民的版本中:

The only workaround I found is to specify the version of the new migration as in:

rake db:migrate version=20080910125745

所以,我想知道:这是一个预期的新的行为

So I'm wondering: is this an expected new behavior?

推荐答案

您应该能够使用

rake db:migrate:up 

要迫使它往前走,但你可能从其他人失踪交错迁移你的团队

to force it to go forward, but then you risk missing interleaved migrations from other people on your team

如果您运行

rake db:migrate 

两次,它会重新应用所有的迁移。

twice, it will reapply all your migrations.

我碰到窗​​户上的SQLite相同的行为,它可能是特定于这样的环境中的错误。

I encounter the same behavior on windows with SQLite, it might be a bug specific to such an environment.

修改 - 我找到了原因。在railstie database.rake任务有以下code:

Edit -- I found why. In the railstie database.rake task you have the following code :

desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
task :migrate => :environment do
  ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
  ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
  Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end

然后在我的环境变量我有

Then in my environment variables I have

echo %Version% #=> V3.5.0f

在红宝石

ENV["VERSION"] # => V3.5.0f
ENV["VERSION"].to_i #=>0 not nil !

因此​​rake任务调用

thus the rake task calls

ActiveRecord::Migrator.migrate("db/migrate/", 0)

和中的ActiveRecord ::迁移,我们有:

and in ActiveRecord::Migrator we have :

class Migrator#:nodoc:
  class << self
    def migrate(migrations_path, target_version = nil)
      case
        when target_version.nil?              then up(migrations_path, target_version)
        when current_version > target_version then down(migrations_path, target_version)
        else                                       up(migrations_path, target_version)
      end
    end

耙分贝:迁移VERSION = 0 是长版耙分贝:迁移:向下

修改 - 我会去更新灯塔的错误,但我在中超公司代理禁止我连接有

Edit - I would go update the lighthouse bug but I the super company proxy forbids that I connect there

在此期间,你可能会尝试取消设置版本调用迁移之前...

In the meantime you may try to unset Version before you call migrate ...

这篇关于耙分贝:迁移没有检测到新的迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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