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?
2 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
1 Comment
Valter Ekholm
Hello. I did like this "rails g migration add_priority_to_article" - but the migration file that was generated had no instruction... instead I used "priority:integer" (ending the g-command) and it worked
The lazy way:
rails g migration add_amount_to_items amount:integer