I’ve just deployed a commit to Heroku which adds a portfolio field to my photos table. I have set default => true on this. Here is an abbreviated look at my schema.rb:
create_table "photos", :force => true do |t|
t.string "name"
t.string "description"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "portfolio", :default => true
end
This worked fine in development and changed all the current photos to have a default value of true for portfolio. So I deployed the updates to Heroku, ran heroku rake db:migrate and heroku restart. It migrated just fine, but all the images have NULL as their default for portfolio. Does anyone know how to get Heroku to change the default value for this in the database? Thank you.
With that migration you are only setting a new default on that column, and that default only applies to new rows, not pre-existing ones which already have a value of NULL.
Like you say, you need to retrospectively set your default into older records as part of your migration: