如何使用长ID的Rails应用程序?如何使用、应用程序、ID、Rails

2023-09-09 21:58:43 作者:眼底尽藏温柔

我如何可以改变(默认)类型的ActiveRecord的标识? int是不够长,长我会preFER。我很惊讶,有没有?长的迁移 - 做一件只需要使用一些十进制

How can I change the (default) type for ActiveRecord's IDs? int is not long enough, I would prefer long. I was surprised that there is no :long for the migrations - does one just use some decimal?

推荐答案

贷http://moeffju.net/blog/using-bigint-columns-in-rails-migrations

class CreateDemo < ActiveRecord::Migration
  def self.up
    create_table :demo, :id => false do |t|
      t.integer :id, :limit => 8
    end
  end
end

查看选项:ID =&GT;假它禁用自动创建id字段的 的 t.integer:ID,:上限=&GT; 8 线将产生64位整型字段

See the option :id => false which disables the automatic creation of the id field The t.integer :id, :limit => 8 line will produce a 64 bit integer field