How to Implement Migration in Rails Application

How to Implement Migration in Rails Application

20 Apr 2021
0 Comments
How to Implement Migration in Rails Application

 

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.

 

Technologies:

  • Ruby on Rails
  • MVC Framework

 

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.

rails db:migrate

The migration file for adding a column will look as mentioned above.




Leave a comment: