Today I Learned

hashrocket A Hashrocket project

Toggle NOT NULL constraints with Rails migrations

You can quickly toggle a "NOT NULL" constraint in a Rails migration with the change_column_null method.

To add the constraint:

change_column_null :users, :email, false

To remove the constraint:

change_column_null :users, :email, true
See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.