undefined method `to_sym’ for nil:NilClass – Ruby on Rails Migration

While trying to do a migration today I received the following message:

undefined method `to_sym’ for nil:NilClass

#After running a trace (rake db:migrate –trace)
undefined method `to_sym’ for nil:NilClass
/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing’

This was the migration:

class AddDefaultValuesToFeedbacks < ActiveRecord::Migration
  def change
    change_column :stores, :total_feedbacks, :integer, :default => 0
    change_column :stores, :rating, :decimal, :precision => 8, :scale => 2, :default => 0

Unfortunately this problem also prevented me from performing any other migrations on the table. I attempted deleting all relevant migration files and then re-running them, restarting the server and rolling back to a previous migration – none of which worked.

Eventually I resorted to exporting the dataset, dropping the table via sqlite3 and recreating it. Thankfully this seems to have worked. The only hint I’ve come across that may explain the cause of this problem, other than typos or referring to non-existant columns, is that it can occur if a migration is screwed over before it finishes and fails to rollback properly.

If anyone else has any concrete answers, please let me know in the comments!

Leave a Reply