John
John

Reputation: 4706

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?

Upvotes: 13

Views: 13834

Answers (2)

We Going Nowhere
We Going Nowhere

Reputation: 306

The lazy way:

rails g migration add_amount_to_items amount:integer

Upvotes: 11

adimitri
adimitri

Reputation: 1296

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

Upvotes: 17

Related Questions