Skip to content

Instantly share code, notes, and snippets.

@freegenie
Created March 12, 2013 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freegenie/5142171 to your computer and use it in GitHub Desktop.
Save freegenie/5142171 to your computer and use it in GitHub Desktop.
Rails migration set null to false with no default
class AddPrivacyToSubscription < ActiveRecord::Migration
def change
add_column :subscriptions, :privacy, :boolean, :default => false, :null => false
change_column_default(:subscriptions, :privacy, nil)
end
end
@freegenie
Copy link
Author

I didn't know change_column_default method. It's indeed very useful when you are introducing a new field on a populated table and you don't' want to set a default value for the new records to come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment