0

Possible Duplicate:
Add a default value to a column through a migration

I know it wouldn't affect existing data, but for every record going forward, I would like for there to be a default value - i.e. not null to be stored in the column.

How do I do that for existing columns without having to drop the columns?

Community
  • 1
  • 1
marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • 1
    see http://stackoverflow.com/questions/7098602/add-a-default-value-to-a-column-through-a-migration – jstim Oct 11 '12 at 23:53
  • 1
    http://stackoverflow.com/questions/8627156/adding-default-true-to-boolean-in-existing-rails-column/8627171#8627171 – Robin Oct 11 '12 at 23:54

1 Answers1

1

Following the links in the comments, this works for me:

change_table :my_model do |t|
     t.change_default :my_column, 0
end

Where 0 is the default value I wanted to set - and :my_column is the name of the column.

Additional Info can be found in the API Docs

marcamillion
  • 32,933
  • 55
  • 189
  • 380