8
在Rails中创建模型时,我忘了添加我想要的列amount
。我以后如何将它添加到模型中?Rails数据库添加列
在Rails中创建模型时,我忘了添加我想要的列amount
。我以后如何将它添加到模型中?Rails数据库添加列
通过与控制台创建一个新的迁移:
rails g migration add_amount_to_items
这应该创建一个迁移是这样的:
class AddAmountToItems < ActiveRecord::Migration
def change
# add_column table_name, :column_name, :column_type
add_column :items, :amount, :integer
end
end
偷懒的方法:
rails g migration add_amount_to_items amount:integer
你好谢谢@ WeGoingNowhere - 什么是适当的,舒适的方式可以长期保存悲伤。如果你不想'快速和肮脏的' – BKSpurgeon
并且不要忘记运行迁移:bin/rake db:migrate – Arthur