Scenario: we already have a Document model, and we want to add
or more columns using a single migration.
From what I've searched and read so far, you just have to edit the migration file. If the migration was already applied, roll back and migrate again.
command to create new model and table with columns : rails g model ModelName col_name1:string col_name2:integer col_name3:text ... command to add more columns under existing table: rails g migration AddColumnToModelName col_name4:string col_name5:integer ...
Rolling back a migration and re-editing it is only safe if that migration is local and has not been pushed out to any repository. Editing a migration that others have applied may cause issues.
The safest way to add columns to an existing table is to just create a new migration:
rails g migration add_public_and_private_to_document public:string private:string
If you use the add_[column_names]_to_[model]
naming convention, rails will work out the appropriate table and create the migration you want.
Have a read here for more info: http://guides.rubyonrails.org/migrations.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With