# Updating model in migration not working

**URL:** <https://www.ruby-forum.com/t/updating-model-in-migration-not-working/127357>\
**Category:** Rails\
**Created:** [January 28, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/updating-model-in-migration-not-working/127357 "2008-01-28T15:57:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![apie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@apie](https://www.ruby-forum.com/u/apie)\
**Post date:** [January 28, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/updating-model-in-migration-not-working/127357/1 "2008-01-28T15:57:57Z")

</div>

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
