Rails Migration to make a column null => true

烂漫一生 提交于 2019-12-31 10:56:52

问题


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


回答1:


Try:

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



回答2:


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.



来源:https://stackoverflow.com/questions/10900778/rails-migration-to-make-a-column-null-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!