How to use long id in Rails applications?

后端 未结 11 1531
天涯浪人
天涯浪人 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条回答
  •  一整个雨季
    2020-11-30 23:11

    You can do it like this:

    class CreateUsers < ActiveRecord::Migration[5.0]
      def change
        create_table :users, id: :bigserial do |t|
          t.string :name
        end
      end
    end
    

提交回复
热议问题