Rails Migration to make a column null => true

Ruby on-Rails-3Migration

Ruby on-Rails-3 Problem Overview


I had originally created a table with column as

t.string   "email",  :default => "", :null => false

The requirement has changed and now I need to allow email to be null. How can I write a migration to make :null => true

Ruby on-Rails-3 Solutions


Solution 1 - Ruby on-Rails-3

change_column_null worked perfectly:

change_column_null :users, :email, true

The reverse has a nice option to update existing records (but not set the default) when null is not allowed.

Solution 2 - Ruby on-Rails-3

Try:

change_column :table_name, :email, :string, null: true

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPykihView Question on Stackoverflow
Solution 1 - Ruby on-Rails-3user1309272View Answer on Stackoverflow
Solution 2 - Ruby on-Rails-3Pratik KhadloyaView Answer on Stackoverflow