如何使用长ID的Rails应用程序? [英] How to use long id in Rails applications?
本文介绍了如何使用长ID的Rails应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何可以改变(默认)类型的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?
推荐答案
贷<一个href="http://moeffju.net/blog/using-bigint-columns-in-rails-migrations">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
这篇关于如何使用长ID的Rails应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文