I am running a program that creates millions of records daily, after running this program for over a year it seems like I have reached the id limit on my postgres database.
The error I am receiving is
django.db.utils.DataError: nextval: reached maximum value of sequence "main_records_id_seq" (2147483647)
Is there a way to extend the maximum id using SQL or the django ORM? Or is there a better solution?
Django uses by default an AutoField
[Django-doc] to specify values for the primary key at the database side. An AutoField
is an IntegerField
[Django-doc], and as the Django documentation says:
An integer. Values from
-2147483648
to2147483647
are safe in all databases supported by Django.
What you can use instead is a BigAutoField
[Django-doc], which will use:
A 64-bit integer, much like an
AutoField
except that it is guaranteed to fit numbers from1
to9223372036854775807
.
If your application generates 2'147'483'647 in one year, you can make use of a BigAutoField
for 4'294'967'298 years.
You thus can define your model as:
class MyModel(models.Model):
id = models.BigAutoField(primary_key=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With