"", :null => false T...">

Rails Migration to create a column null => true

I originally created a table with a column

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

The requirement has changed, and now I need the email to be empty. How to write a migration to do: null => true

+49
ruby-on-rails-3 migration
Jun 05 2018-12-12T00:
source share
2 answers

Try:

 change_column :table_name, :email, :string, :null => true 
+69
Jun 05 2018-12-12T00:
source share

I could not get the above solution to work with Active Record 4.0.8 and Postgresql 9.3

However, change_column_null worked fine.

 change_column_null :users, :email, true 

Reverse has the good ability to update existing records (but not set by default) when null is not allowed.

+48
Aug 20 '14 at 7:21
source share



All Articles