What is Migration?
A technique used to create changes in the database, the Rails migration is a tool for modifying an application’s database schema. While creating a database, use migration to add, remove, rename, change the data type, adding a reference, adding a foreign key, etc.
Need of migration:
To alter/change the existing table in the database.
Advantages of migration:
It is a useful tool to make changes to the application’s database whenever required.
Let's understand the step-by-step approach to applying Migration in Rails application.
Step 1: Create a new Rails application and database.
Step 2: Create model and controller in the application and draft code to create records.
Step 3: Create a migration file to add an extra column to the table.
The application schema.rb file with all the migration will look as mentioned above.
Step 4: After drafting the code to add the fields in the table, run the below command and start the server.
The migration file for adding a column will look as mentioned above.