The solution depends on a few things.
Is the default value dependent on other information available at creation time?
Can you wipe the database with minimal consequences?
If you answered the first question yes, then you want to use Jim's solution
If you answered the second question yes, then you want to use Daniel's solution
If you answered no to both questions, you're probably better off adding and running a new migration.
class AddDefaultMigration < ActiveRecord::Migration
def self.up
change_column :tasks, :status, :string, :default => default_value, :null => false
end
end
:string can be replaced with any type that ActiveRecord::Migration recognizes.
CPU is cheap so the redefinition of Task in Jim's solution isn't going to cause many problems. Especially in a production environment. This migration is proper way of doing it as it is loaded it and called much less often.