If you are a Rails Developer then you might have seen a decimal number in the migration file and probably no doubt that you have ignored it every time so I have. But today let’s face and find it out, what it is !!!

class AddFewColumns < ActiveRecord::Migration[7.1]
 #data alteration codde

Let’s discuss what it is
The [7.1] within ActiveRecord::Migration[7.1] specifies the version of ActiveRecord that this migration is intended to be run under.

  • In Rails, each major version of ActiveRecord might introduce changes or enhancements to the way migrations work or how they interact with the database. By specifying the version, you are indicating which version of ActiveRecord you expect your migration to be compatible with.
  • In this case, [7.1] suggests that the migration is intended to be run with ActiveRecord version 7.1. It helps Rails maintain compatibility as you might have migrations created with different versions of ActiveRecord in the same project.
  • It’s important to note that [7.1] in this context is specific to Rails 7.1 or a later version of ActiveRecord. If you’re using a different version of Rails or ActiveRecord, the version number in the migration file may be different.

In a more simplified way
Imagine it like this:

  • You have different versions of a software tool, let’s say ActiveRecord (a part of Ruby on Rails), which evolves over time.
    (make sure you are imagining with me as per the above deal.)
  • Your migration is like a set of instructions that tells the tool how to change the database structure.
  • You want to make sure these instructions work correctly with the version of the tool you’re using.
  • So, you specify [7.1] to say, “Hey, Dear migrator please use these instructions that are meant for ActiveRecord version 7.1.”

It’s like telling a recipe book which edition it’s written for, making sure you follow the right steps with the right recipe. Otherwise, it can spoil your application meal.
So it is what it is..!

Support On Demand!

Ruby on Rails