Updating model in migration not working

Hi there

I have a model that needs to get an extra field. So, I created a
migration
to add the field

add_column :my_models, :my_field, :string

This works fine as per usual. However, I want to populate the field with
a
value so I do this

MyModel.find(:all).each do |m|
m.my_field = “value”
puts m.my_field
puts m.save
m.reload
puts m.my_field
end

lower in the self.up part of the migration.

When I run the migration I get this output:

“value”
true
nil

I have confirmed that the field is populated in a before_filter by
outputting the field value before it is saved. I have also confirmed
that
the ‘my_field’ field value is “value” in def after_save but, if I find
an
instance of MyModel from the db, I get my_field = nil.

Any ideas?

Ivor

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs