Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails database add column

When creating a model in Rails, I forgot to add a column amount that I want. How can I add it to the model later?

like image 887
John Avatar asked Oct 20 '12 00:10

John


1 Answers

Create a new migration via the console with:

rails g migration add_amount_to_items

This should create a migration something like this:

class AddAmountToItems < ActiveRecord::Migration
  def change
    # add_column table_name, :column_name, :column_type
    add_column :items, :amount, :integer
  end
end
like image 69
adimitri Avatar answered Sep 19 '22 13:09

adimitri