在下面的 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
uj5u.com熱心網友回復:
ActiveRecord::Migration類具有[] 此處定義的鏈接到兼容性模塊的方法。
通過指定運行遷移的 rails 版本,確保在Migration升級 rails 時類的新功能不會與遷移沖突。
Compatibility在模塊的評論中有一個很好的解釋。
# This file exists to ensure that old migrations run the same way they did before a Rails upgrade.
# e.g. if you write a migration on Rails 6.1, then upgrade to Rails 7, the migration should do the same thing to your
# database as it did when you were running Rails 6.1
#
# "Current" is an alias for `ActiveRecord::Migration`, it represents the current Rails version.
# New migration functionality that will never be backward compatible should be added directly to `ActiveRecord::Migration`.
#
# There are classes for each prior Rails version. Each class descends from the *next* Rails version, so:
# 7.0 < 7.1
# 5.2 < 6.0 < 6.1 < 7.0 < 7.1
#
# If you are introducing new migration functionality that should only apply from Rails 7 onward, then you should
# find the class that immediately precedes it (6.1), and override the relevant migration methods to undo your changes.
#
# For example, Rails 6 added a default value for the `precision` option on datetime columns. So in this file, the `V5_2`
# class sets the value of `precision` to `nil` if it's not explicitly provided. This way, the default value will not apply
# for migrations written for 5.2, but will for migrations written for 6.0.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/431888.html
