Increase ActiveModel ID Range to 8 byte

喜欢而已 提交于 2019-12-13 06:39:20

问题


I've been digging around to see how I could have all my newly and subsequent Model id's to have a limit of 8 byte. Answers show how to when adding a new table column; I want whenever I create a new Model, it would automatically has a limit of 8 byte. Possible?

When creating a new model, I get:

ActiveModel::RangeError: 36565651767 is out of range for ActiveModel::Type::Integer with limit 4

Where to change this limit from 4 to 8?


回答1:


A possible duplicate but since there will be errors:

you can't redefine the primary key column 'id'. To define a custom primary key, pass { id: false } to create_table.

Which means your table should look like this:

class MyModels < ActiveRecord::Migration[5.0]
  def change
    create_table :my_models, {id: false } do |t|
      t.column   :id, limit: 8
      ...
     end
  end
end


来源:https://stackoverflow.com/questions/39293995/increase-activemodel-id-range-to-8-byte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!