将ActiveModel ID范围增加到8个字节 [英] Increase ActiveModel ID Range to 8 byte
问题描述
我一直在进行挖掘以了解如何将我所有的新模型ID和后续模型ID的长度限制为8个字节。答案显示了添加新表列时的操作方式。我想每创建一个新的 Model
时,它就会自动具有8个字节的 limit
。
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超出ActiveModel :: Type :: Integer(限制为4)的范围
ActiveModel::RangeError: 36565651767 is out of range for ActiveModel::Type::Integer with limit 4
在哪里将此限制从4更改为8?
Where to change this limit from 4 to 8?
推荐答案
A 可能重复,但由于会出现错误:
A possible duplicate but since there will be errors:
t重新定义主键列 id。要定义自定义主键,请将{id:false}传递到create_table。
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
这篇关于将ActiveModel ID范围增加到8个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!