如何在 Rails 应用程序中使用长 ID? [英] How to use long id in Rails applications?

查看:20
本文介绍了如何在 Rails 应用程序中使用长 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 ActiveRecord 的 ID 的(默认)类型?int 不够长,我宁愿长.我很惊讶没有 :long 迁移 - 是否只使用一些小数?

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 =>false 禁用自动创建 id 字段
  • t.integer :id, :limit =>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
    • 这篇关于如何在 Rails 应用程序中使用长 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆