In Django, if you don't specify primary key
, it will add an integer autofield
. My question is that if this incremental id, reaches integer limit, what is expected to happen after?

- 2,232
- 1
- 18
- 38
2 Answers
The database will raise an error and inserting whatever you're inserting will fail.
If you are using MySQL, the error will probably be something like this : ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
.
The limit for django's auto increment id is 2,147,483,647. So it's pretty unlikely that you will hit this limit unless you're storing extremely large amounts of data. If you are using large amounts of data, you can use the bigint
type for the field instead.

- 407
- 4
- 13
in postgresql maximum amount of ID fields is 9223372036854775807
if your database have these amount of record its not work. assume a simple query with ordering take more than a year to execute
or if each record take 100 Byte (with index and ... data its too few for each record) this amount of record takes 838860700 TB storage. there is no storage to store these amount of data in all over the world.

- 1,778
- 16
- 22
-
This is not true. although the max might be 9223372036854775807 for postgres, django uses an integer field and not a bigautofield which you are referencing. – Yang K Aug 15 '18 at 05:01
-
I don't have that amount of data but my row are deleted and inserted frequently. and previous ids are not used again. So reaching limit is possible – mohammad Aug 15 '18 at 05:11
-
I assume you use big auto field. in integer field limitation is 2,147,483,647 and Its not reachable. but if you want this amount of record you can do one of these. 1- convert youf field to big integer auto field. 2- if your old data removed from database you can reset sequence of your model when you reach this amount . but it can cause your database not to work. be aware of old records. – vorujack Aug 15 '18 at 05:20