What’s does the [5.0] in Rails 5’s ActiveRecord::Migration mean?

与世无争的帅哥 提交于 2019-12-30 07:53:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!