本文介绍了将ActiveModel ID范围增加到8个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在以了解如何将我所有的新模型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:
在哪里将此限制从4更改为8?
Where to change this limit from 4 to 8?
推荐答案
A ,但由于会出现错误:
A possible duplicate but since there will be errors:
这意味着您的表应如下所示:
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个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!