0

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?

Community
  • 1
  • 1
Sylar
  • 11,422
  • 25
  • 93
  • 166

1 Answers1

0

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
Community
  • 1
  • 1
Sylar
  • 11,422
  • 25
  • 93
  • 166