Add a default value to a column through a migration Add a default value to a column through a migration ruby ruby

Add a default value to a column through a migration


Here's how you should do it:

change_column :users, :admin, :boolean, :default => false

But some databases, like PostgreSQL, will not update the field for rows previously created, so make sure you update the field manaully on the migration too.


change_column_default :employees, :foreign, false


For Rails 4+, use change_column_default

def change  change_column_default :table, :column, valueend