在没有默认值的列上使用 change_column_default 时,'from' 值应该是多少?

When using change_column_default on a column with no default, what should be the 'from' value?

这是我创建的 table 迁移。请注意,我没有提供 price.

的默认值
class CreateProducts < ActiveRecord::Migration[5.0]
  def change
    create_table :products do |t|
      t.string :name
      t.decimal :price, precision: 8, scale: 2

      t.timestamps
    end
  end
end

现在我想设置一个默认值。根据 the Migration guide,我应该提供 from 以使其可逆。我应该提供什么价值?

class ChangeProductsPriceDefault < ActiveRecord::Migration[5.0]
  def change
    change_column_default :products, :price, from: 'WHAT_TO_WRITE_HERE?', to: 0
  end
end

"No default"表示默认为NULL,所以:

change_column_default :products, :price, from: nil, to: 0

有关于nil默认的说明:http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-change_column_default