不是我发现的Postgres的第一个Rails 4迁移错误,如果它确实是一个bug。
我无法弄清楚为什么这种非常简单的迁移不起作用:
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, { default: false, null: false }
end
end
我已经尝试了有和没有花括号。这是错误:
== AddAdminToUsers:迁移========================================== ====== - add_column(:users,:admin,:boolean,{:default =&gt; false,:null =&gt; false}) 耙子流产了! 发生错误,此操作和所有后续迁移都已取消:
wrong number of arguments (2 for 1)/Users/me/.rvm/gems/ruby-2.0.0-p353@myapp/gems/rails_best_practices-1.15.0/lib/rails_best_practices/core_ext/object.rb:7:in `try'
/Users/me/.rvm/gems/ruby-2.0.0-p353@myapp/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:723:in `translate_exception'
/Users/me/.rvm/gems/ruby-2.0.0-p353@myapp/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:439:in `rescue in log'
/Users/me/.rvm/gems/ruby-2.0.0-p353@myapp/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `log'
/Users/me/.rvm/gems/ruby-2.0.0-p353@myapp/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 :(得分:1)
这似乎是rails_best_practices
gem中的一个错误。当我卸载那个gem时,代码可以运行。我会通知宝石维护者。