Migration fails need to reload attributes from model?


I have a problem with a migration sequence. Running rake db:migrate from
the start (empty db) fails at migration 20. The problem it appears, is
that the new attributes are not reloaded. I have tried adding "load
‘state.rb’ to the migration but this also fails.

If i run the migration again from the failed point it succeeds.

i would like to be able to run the complete set of migrations to create
the db.

Thanks in advance for any help.

== RePopulateStates: migrating

rake aborted!
undefined method page_name=' for #<State:0x355f728> /Users/adam/Projects/boomkat/acquire.boomkat.com/trunk/vendor/rails/activerecord/lib/active_record/base.rb:1934:inmethod_missing’
send' /Users/adam/Projects/boomkat/acquire.boomkat.com/trunk/vendor/rails/activerecord/lib/active_record/base.rb:1749:inattributes=’

migration 19) The first migration adds 4 columns.

add_column :states, :page_name, :string, :default => ''
add_column :states, :body_class, :string, :default => ''
add_column :states, :path, :string, :default => ''

migration 20) The second clears out the model and repopulates:

State.create!(:name => ‘received’, :page_name => ‘Inbox’,
:body_class => ‘inbox’, :path=> ‘releases_path’,
:empty_text => ‘No releases have have imported at this time.’)

State.create!(:name => 'accepted',  :page_name => 'Edit and

Publish’, :body_class => ‘edit_and_publish’, :path=>
‘publish_releases_path’, :empty_text => ‘No releases have have
completed publication at this time.’)

On May 31, 2007, at 9:15 AM, Adam M.ox wrote:

migration 20) The second clears out the model and repopulates:
completed publication at this time.')
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

def self.up
add_column :products, :source, :string
Product.update_all(‘source = “something”’)
add_index :products, [ :source, :vendor, :code ], :name =>

def self.down
remove_index :products, :name => ‘products_source_index’
remove_column :products, :source

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

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


Rob B. http://agileconsultingllc.com
[email protected]

Thanks bob!!

Im not sure how i missed the reset_column_information method. Ill blame
the hot chilli thai meal and beer i had at lunch.