2014-02-18 21 views
0

不是我发现的第一个Rails 4迁移bug,如果确实是一个bug。Rails 4简单迁移Postgres上的错误

我想不通为什么这个极其简单的迁移将无法正常工作:

class AddAdminToUsers < ActiveRecord::Migration 
    def change 
    add_column :users, :admin, :boolean, { default: false, null: false } 
    end 
end 

我已经使用和不使用大括号试了一下。这是错误:

== AddAdminToUsers:migrating ==================================== ============ - add_column(:users,:admin,:boolean,{:default => false,:null => false}) rake aborted! 发生错误,这和所有后来迁移取消:

wrong number of arguments (2 for 1)/Users/me/.rvm/gems/[email protected]/gems/rails_best_practices-1.15.0/lib/rails_best_practices/core_ext/object.rb:7:in `try' 
/Users/me/.rvm/gems/[email protected]/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:723:in `translate_exception' 
/Users/me/.rvm/gems/[email protected]/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:439:in `rescue in log' 
/Users/me/.rvm/gems/[email protected]/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `log' 
/Users/me/.rvm/gems/[email protected]/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute' 

documentation是很清楚,这是可以的:

add_column(table_name, column_name, type, options): 
    Adds a new column to the table called table_name named 
    column_name specified to be one of the following types: 
    :string, :text, :integer, :float, :decimal, :datetime, 
    :timestamp, :time, :date, :binary, :boolean. 
A default value can be specified by passing an options 
    hash like { default: 11 }. 
Other options include :limit and :null (e.g. { limit: 50, null: false }) 

而且,为什么是rails-best-practices宝石抱怨?我没有援引它。

+0

删除花括号。看看是否有帮助。 – Mab879

+0

我做了同样的错误。 – AKWF

+0

仅当我删除“布尔”后的所有内容时才有效。 – AKWF

回答

1

这似乎是rails_best_practices宝石中的一个错误。当我卸载该宝石时,代码正常工作。我会通知宝石维护者。

+1

我认为这是一个已知的问题。该版本已从红宝石宝石中抽出。升级到版本1.15.1应该解决问题并保持安装。 – Mab879

+0

是的,事实确实如此。升级立即解决了问题。宝石团队的巨大反应也。 – AKWF