gpt4 book ai didi

ruby-on-rails - 在迁移中生成类型为 'double' 的列 - Ruby on rails

转载 作者:行者123 更新时间:2023-12-04 17:37:34 25 4
gpt4 key购买 nike

我需要在我的数据库中创建一个 double 类型的列,我知道在 ruby​​ 中没有 double 类型,为了模拟这种类型的值我有使用 :scale:precision

我该如何解决这个问题?

最佳答案

您可以在迁移中指定精度和比例。

class AddCostToBookings < ActiveRecord::Migration
def change
add_column :bookings, :cost, :decimal, precision: 10, scale: 2
end
end

Precision defines the precision for the decimal fields, representing the total number of digits in the number.

Scale defines the scale for the decimal fields, representing the number of digits after the decimal point.

关于ruby-on-rails - 在迁移中生成类型为 'double' 的列 - Ruby on rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56093518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com