【发布时间】:2017-03-08 06:54:14
【问题描述】:
这是我的创建表迁移。请注意,我没有提供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
【问题讨论】:
-
写自:nil @wit。
标签: ruby-on-rails rails-activerecord rails-migrations