Add Rails Database Column

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

+8
ruby-on-rails ruby-on-rails-3
source share
2 answers

Create a new migration through 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 
+11
source share

Lazy way:

 rails g migration add_amount_to_items amount:integer 
+6
source share

All Articles