添加的列在下一个迁移文件中无法访问

时间:2016-10-23 09:26:52

标签: ruby-on-rails rails-migrations

我通过迁移向表中添加了一列,但是我无法访问后续迁移文件中添加的列。

当我执行rake db:migrate时,迁移会中止,但是当我再次执行迁移时,迁移成功,不确定我做错了什么。任何帮助,将不胜感激。感谢。

下面是我添加列

的代码

**

class AddIsDispatchToUsers < ActiveRecord::Migration
  def change
    add_column :users, :is_dispatch, :boolean, :default=>false
  end
end

**

现在,当我尝试访问下一个迁移文件中的列时,它会失败。

后续迁移文件的代码如下

service_member = Member.create(:is_dispatch =&gt; true)

以下是它产生的错误

unknown attribute: is_dispatch/Users//.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.1.12/lib/active_record/base.rb:1764:in `block in assign_attributes'
/Users//.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.1.12/lib/active_record/base.rb:1758:in `each'
/Users//.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.1.12/lib/active_record/base.rb:1758:in `assign_attributes'
/Users//.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.1.12/lib/active_record/base.rb:1578:in `initialize'
/Users//.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.1.12/lib/active_record/base.rb:508:in `new'
/Users//.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.1.12/lib/active_record/base.rb:508:in `create'
/Users//Desktop/RailsDevelopement//db/migrate/20161003121452_add_dispatch_services.rb:11:in `up'

1 个答案:

答案 0 :(得分:1)

您是否在同一次迁移中User.reset_column_information之后尝试add_column