问题
A migration I created in a Rails 5 application had 5.0
passed into a method:
class CreateVariableKeys < ActiveRecord::Migration[5.0]
...
end
I would like to know what the [5.0]
means.
回答1:
It is a class method of ActiveRecord::Migration
and is defined here.
It allows us to select the version of migrations we wish to use between 4.2
and 5.0
. The method throws a:
"Unknown migration version ... "
error if an incompatible version is passed as an argument.
Production ready versions of ActiveRecord
don’t have that method so it should go away as soon as Rails 5 goes out of beta.
回答2:
This blog has more info too
It seems to be there so that you don't have to upgrade old migrations, when moving from rails 4 to rails 5. (There are some small changes in the migrations API).
来源:https://stackoverflow.com/questions/35302197/what-s-does-the-5-0-in-rails-5-s-activerecordmigration-mean