不是我发现的第一个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
宝石抱怨?我没有援引它。
删除花括号。看看是否有帮助。 – Mab879
我做了同样的错误。 – AKWF
仅当我删除“布尔”后的所有内容时才有效。 – AKWF