django id integer limit

╄→гoц情女王★ 提交于 2019-11-29 13:27:55

Adding this as an answer. Django maps this to serial columns which means that the maximum value is in the 2 billion range ( 2,147,483,647 to be exact). While that is unlikely to be an issue for most applications, if you do, you could alter the type to become a bigint instead and this would make it highly unlikely you will ever reach the end of 64-bit int space.

Adding new info for Django 2.x:


Djangos AutoField is an IntegerField. The docs for IntegerField say:

Values from -2.147.483.648 to 2.147.483.647 are safe in all databases supported by Django.

AutoField per default only uses positive numbers, so the values can go from 1 to 2.147.483.647.


Since Django 1.10 there is also an BigAutoField, which is very similar to the BigIntegerField. The docs for BigAutoField say:

A 64-bit integer [...] that is guaranteed to fit numbers from 1 to 9.223.372.036.854.775.807.

Now, the docs don't say it explicitly for this field, but by using the words is garanteed to fit, I assume that applies for all databases supported by Django.

As others have mentioned whether you use int or bigint, respectively you have 2.147.483.648 or 9.223.372.036.854.775.808 values.

If you think to exceed those numbers, you can do sharding. In short, sharding is a way of horizontally partitioning your data by storing different rows of the same table in multiple tables across multiple databases.

There are available many sharding libraries for Django (e.g. django-sharding)

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