0

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.

3
  • Remove the curly braces. See if that helps. Commented Feb 18, 2014 at 1:06
  • Only works if I delete everything after "boolean". Commented Feb 18, 2014 at 1:07
  • Are you using rails 4.0.2? Commented Feb 18, 2014 at 1:13

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I think its was a known issue. That version has been yanked from ruby gems. Upgrade to version 1.15.1 that should fix the issue and keep the them installed.
Yep, that was indeed the case. The upgrade fixed the problem instantly. Great response by the gem team also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.