Rails Migration to make a column null => true

前端 未结 2 1959
礼貌的吻别
礼貌的吻别 2021-02-02 05:04

I had originally created a table with column as

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

The requirement has changed and n

相关标签:
2条回答
  • 2021-02-02 05:24

    Try:

    change_column :table_name, :email, :string, :null => true
    
    0 讨论(0)
  • 2021-02-02 05:41

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

    However 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.

    0 讨论(0)
提交回复
热议问题