Rails 4 add new column or field in model

半腔热情 提交于 2019-12-04 03:44:14

问题


I try to add new column into existing model in rubyonrails. How can I add single or multiple field into my existing model.


回答1:


if you want to add a new column then

run rails generator with Add[column]To[model] format followed by column

$ rails g migration AddBioToNameOfModels bio:text
invoke  active_record
create    db/migrate/YYYYMMDDHHMMSS_add_bio_to_name_of_models.rb

then run

rake db:migrate


来源:https://stackoverflow.com/questions/30528877/rails-4-add-new-column-or-field-in-model

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