How to use long id in Rails applications?

后端 未结 11 1547
天涯浪人
天涯浪人 2020-11-30 22:24

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 on

11条回答
  •  猫巷女王i
    2020-11-30 22:58

    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

提交回复
热议问题