[英]How to generate model with restriction on data precision, scale in ruby on rails
I am trying to generate the following a model named PriceUsdOneMinIntervals
, but unable to apply the format for precision and scale correctly, can someone please advise how to correct the syntax in the following: 我正在尝试生成以下名为
PriceUsdOneMinIntervals
的模型,但是无法正确应用格式以进行精确度和缩放,有人可以建议以下方法来纠正语法:
rails generate model PriceUsdOneMinInterval unix_timestamp:integer usd_high:decimal :precision[20] :scale[8] usd_low:decimal :precision[20] :scale[8] usd_open:decimal :precision[20] :scale[8] usd_close:decimal :precision[20] scale[8]
I have referred to this api while making the above statement. 在进行上述声明时,我已引用此 api。
TRy this 尝试这个
rails generate model PriceUsdOneMinInterval :unix_timestamp, :integer,
:usd_high, :decimal, precision: 20, scale: 8, :usd_low, :decimal, precision: 20,
scale: 8, :usd_open, :decimal, precision: 20, scale: 8,
:usd_close, :decimal, precision: 20, scale: 8
OR 要么
generate migration with just field names and data_types and then change you can change the values in migration 仅使用字段名称和data_types生成迁移,然后更改即可更改迁移中的值
def change
add_column :price_usd_one_min_intervals, :unix_timestamp, :integer
add_column :price_usd_one_min_intervals, :usd_high, :decimal, precision: 20, :scale: 8
add_column :price_usd_one_min_intervals, :usd_low, :decimal, precision: 20, scale: 8
add_column :price_usd_one_min_intervals, :usd_open, :decimal, precision: 20, scale: 8
add_column :price_usd_one_min_intervals, :usd_close, :decimal, precision: 20, scale: 8
end
rails g model PriceUsdOneMinInterval \
unix_timestamp:integer \
'usd_high:decimal{20,8}' \
'usd_low:decimal{20,8}' \
'usd_open:decimal{20,8}' \
'usd_close:decimal{20,8}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.