简体   繁体   中英

How to update attribute from not null to allow null in rails migrations

I want to do a column from my table from not null to allow null through rails migrations? How to do this? Do i change the original migration which created the table or write a new one? And what to do in it.

You need change_column : http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_column

Create a new migration file with this

change_column :my_table, :my_column, :integer, :null => true

Or you can use a specialised command for this ( change_column_null ):

change_column_null :my_table, :my_column, true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM