【问题标题】:What integer data type has a scope greater than integer in rails? [duplicate]什么整数数据类型的范围大于 Rails 中的整数? [复制]
【发布时间】:2019-10-19 21:17:48
【问题描述】:
我用字段:price 初始化了一个模型。该字段的值最小值为一百万,我不知道在迁移文件中使用哪种数据。
class CreateTours < ActiveRecord::Migration[5.2]
def change
create_table :tours do |t|
t.references :detail, foreign_key: true
t.integer :price
t.datetime :start_date
t.integer :tour_quantity
t.timestamps
end
end
end
【问题讨论】:
标签:
ruby-on-rails
database-migration
【解决方案1】:
您可以在 ruby 命令行中尝试这些命令并观察输出。它不仅可以处理百万,还可以处理十亿。
puts 1_000_000_000_000_000_000_000_000_000_000_000.instance_of? Fixnum
puts 1_000_000_000_000_000_000_000_000_000_000_000.instance_of? Bignum
puts 1_000_000_000_000_000_000_000_000_000_000_000.instance_of? Integer
从 Ruby 2.5.0 开始,它将返回
弃用,
弃用,
是的
是的,Bignum 和 Fixnum 现在合并为一种类型 Integer