Ruby on Rails, rake migrate add_column fails with The error occurred while evaluating nil.[]

This one had me stumped for a while:

I was attempting to add some columns using rake migrations but kept getting this error:


rake aborted!
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]

when running the migration below. Unfortunately it was the first time I'd used add_column so my immediate assumption was that I'd done something wrong.


class AddVatAndDisplayColumns < ActiveRecord::Migration
def self.up   
   add_column :companies, :help, :int, :default => 1
   add_column :jobs, :start_job, :date, :default => '2007-1-1'
   add_column :jobs, :display, :boolean, :default => true
end
 def self.down    
    remove_column :companies, :vat_quarter
    remove_column :jobs, :start_job 
    remove_column :jobs, :display
  end
end

The answer was simple, add_column doesn't like the :int key. Changed the :int to :integer and the script worked fine. It would have been nice if the error message was less cryptic.

Your rating: None Average: 5 (1 vote)

You're the only one who had the answer to this question!