Can I pass default value to rails generate migration?

后端 未结 4 904
执念已碎
执念已碎 2020-12-29 19:39

I want to know if I can pass a default value to the rails g migration command. Something like:

 $ rails generate migration add_         


        
4条回答
  •  温柔的废话
    2020-12-29 20:15

    Rails migration generator does not handle default values, but after generation of migration file you should update migration file with following code

    add_column :users, :disabled, :boolean, default: false
    

    you can also see this link - http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

提交回复
热议问题