In the development of any practical application, you will be doing quite a few migrations which are basically DDL (data definition language) statements. In real life, you will have several environments (development, test, production, etc.) and it is highly possible that you will be changing the development database while you have a version in production. For this reason, the Rails way is to generate a new migration for any changes to the database instead of making direct changes to existing migration file.
So, familiarize yourself with migrations.
For the specific question, you can do:
rails g migration add_attributes_to_products attr1 attr2 attr3
This will generate a new migration file for adding 3 new attributes to products table (to the Product model). The default type for the attributes is string
. For others, you have specify it like:
rails g migration add_attributes_to_products attr1:integer attr2:text attr3:enum
http://guides.rubyonrails.org/migrations.html#using-the-change-method
– Hellenismt.integer :product_type
. My method while working on development was change directly to that migration even if after it migrated, and when it ready to be push, what I do just reset my db or re-create my db. That way make make migration file cleaner. Just share, hope can help. – Corium