If I create a table with rails generate migration
, I can add an extra column to it later by creating a new migration. I could also rollback the original migration and then edit it to include the extra column.
//Create the model including the migration
$ rails generate model Foo bar:string
//Perform the migration
$ rake db:migrate
//Create the add column migration
$ rails generate migration add_foobar_to_foos foobar:string
//Perform the new migration
$ rake db:migrate
//Create the model including the migration
$ rails generate model Foo bar:string
//Perform the migration
$ rake db:migrate
//Rollback the migration
$ rake db:rollback
//Edit the original migration file
//Perform the new migration
$ rake db:migrate
What is the correct/best way to accomplish this task and why?
Migration tables are files that are created by an administrator. They are used to implement the advanced capabilities of Group Policy object (GPO) import and copy operations. A migration table can contain information about references to security principals, to Universal Naming Convention (UNC) paths, or to both.
database\migration\add_new_column_to_products_table.php Now you can run migrate command to add this new field. Simply you can run below command to auto add a new field. Hope it can help you. Laravel Migration example tutorial, in this tutorial you have learned how to add new column to a table without losing data.
Ill go with method 1. why? because if other developers/machines are working with this environment you can get an inconstant state due to the fact that they might need to rollback at the right time in order to maintain correct db structure.
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