在Rails中创建模型时,我忘记添加我想要的
amount
列。我该如何在模型之后添加它?通过控制台创建新的迁移:
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