Migration fails need to reload attributes from model?

Whenever you use a Model class in a migration, you should define it *within* the migration class. This avoids problems related to the state of the model.

For example:

class AddProductSource < ActiveRecord::Migration
   class Product < ActiveRecord::Base
   end

   def self.up
     add_column :products, :source, :string
     Product.reset_column_information
     Product.update_all('source = "something"')
     add_index :products, [ :source, :vendor, :code ], :name => 'products_source_index'
   end

   def self.down
     remove_index :products, :name => 'products_source_index'
     remove_column :products, :source
   end
end

You also need to call the .reset_column_information to force ActiveRecord to notice the changes that the migration has made to the database.

Try putting a "class State < ActiveRecord::Base; end" inside your migration 20 and see if that clears things up.

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com