[7.1] 在迁移中意味着什么
在下面的 ruby 代码中,[7.1]
是什么意思?
class AddInitialProducts < ActiveRecord::Migration[7.1]
def up
5.times do |i|
Product.create(name: "Product ##{i}", description: "A product.")
end
end
def down
Product.delete_all
end
end
In below ruby code, what does [7.1]
mean?
class AddInitialProducts < ActiveRecord::Migration[7.1]
def up
5.times do |i|
Product.create(name: "Product ##{i}", description: "A product.")
end
end
def down
Product.delete_all
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ActiveRecord::Migration
类具有方法[]
已定义这里链接到兼容性模块。通过指定正在运行迁移的 Rails 版本,可以确保在升级 Rails 时
Migration
类的新功能不会与您的迁移发生冲突。Compatibility
模块的注释中有很好的解释。ActiveRecord::Migration
class has the method[]
defined here that links to the Compatibility module.By specifying the version of rails you are running the migration on you make sure that new functionality of the
Migration
class does not conflict with your migration if you upgrade rails.There is a good explanation in a comment of the
Compatibility
module.