How to use long id in Rails applications?

Björn picture Björn · Jul 1, 2009 · Viewed 37.3k times · Source

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?

Answer

Notinlist picture Notinlist · May 3, 2011

Credits to 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
  • 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