How to use long id in Rails applications?

后端 未结 11 1543
天涯浪人
天涯浪人 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 22:55

    I wrote a gem called activerecord-native_db_types_override that lets you alter the datatypes that will be used in your migrations.

    In your Gemfile, add:

    gem 'activerecord-native_db_types_override'
    

    then in config/environment.rb, to use long ids in postgres, add:

    NativeDbTypesOverride.configure({
      postgres: {
        primary_key: { name: "bigserial primary key"}
      }
    })
    

    See its README for up-to-date info.

提交回复
热议问题