Reputation: 12224
Not the first Rails 4 migration bug for Postgres that I've found, if indeed it is a bug.
I can't figure out why this extremely simple migration won't work:
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, { default: false, null: false }
end
end
I have tried it with and without the curly braces. Here is the error:
== AddAdminToUsers: migrating ================================================ -- add_column(:users, :admin, :boolean, {:default=>false, :null=>false}) rake aborted! An error has occurred, this and all later migrations canceled:
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'
The documentation is very clear that this is allowed:
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 })
Also, why is the rails-best-practices
gem complaining? I'm not invoking it.
Upvotes: 0
Views: 94
Reputation: 12224
This appears to be a bug in the rails_best_practices
gem. When I uninstall that gem, the code works. I will inform the gem maintainer.
Upvotes: 1