這是我創建表遷移。請注意,我沒有提供price
的默認值。在沒有默認值的列上使用change_column_default時,應該是「from」值?
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
寫的:無@wit。 – Saran