Django主键有多大?

时间:2022-09-06 16:23:40

Is there a maximum value as to how high pk values for a model can get? For example, for something like an activity feed model, the pk's can get really large.

模型的pk值有多高可以达到最大值吗?例如,对于像活动Feed模型这样的东西,pk可能变得非常大。

Ex, "Kyle liked this post", "Alex commented on this post" etc..As you can see, for every action, an activity feed object is created. Is there some sort of maximum threshold that will be reached? I've done some research but haven't found a concise answer. If there is some limit, how can one overcome this?

例如,“Kyle喜欢这篇文章”,“Alex评论了这篇文章”等等。你可以看到,对于每个动作,都会创建一个活动供稿对象。是否会达到某种最大阈值?我做了一些研究,但没有找到简明的答案。如果有一些限制,怎么能克服这个?

I currently use PostgreSQL as my database.

我目前使用PostgreSQL作为我的数据库。

2 个解决方案

#1


6  

Django's auto-incrementing IDs are AutoFields, a subclass of IntegerField. It will generate the primary keys as PostgreSQL integer, which are signed 32-bit integers with a maximum value of 2147483647, a little over 2 billion.

Django的自动递增ID是AutoFields,它是IntegerField的子类。它将生成主键作为PostgreSQL整数,它是带符号的32位整数,最大值为2147483647,略高于20亿。

#2


-4  

I'm gonna take a guess and assume that postgreSQL stores primary keys as 64 bits unsigned integers. If this is the case, then you can have up to 2^64 different values. Even with a 32 bits integer, that leaves us with 4294967296 possibilities. Unless you are twitter or facebook, you should never be annoyed with this kind of limit.

我要猜测并假设postgreSQL将主键存储为64位无符号整数。如果是这种情况,那么您最多可以有2 ^ 64个不同的值。即使使用32位整数,也会留下4294967296种可能性。除非你是推特或脸书,否则你不应该对这种限制感到恼火。

#1


6  

Django's auto-incrementing IDs are AutoFields, a subclass of IntegerField. It will generate the primary keys as PostgreSQL integer, which are signed 32-bit integers with a maximum value of 2147483647, a little over 2 billion.

Django的自动递增ID是AutoFields,它是IntegerField的子类。它将生成主键作为PostgreSQL整数,它是带符号的32位整数,最大值为2147483647,略高于20亿。

#2


-4  

I'm gonna take a guess and assume that postgreSQL stores primary keys as 64 bits unsigned integers. If this is the case, then you can have up to 2^64 different values. Even with a 32 bits integer, that leaves us with 4294967296 possibilities. Unless you are twitter or facebook, you should never be annoyed with this kind of limit.

我要猜测并假设postgreSQL将主键存储为64位无符号整数。如果是这种情况,那么您最多可以有2 ^ 64个不同的值。即使使用32位整数,也会留下4294967296种可能性。除非你是推特或脸书,否则你不应该对这种限制感到恼火。