0

In my application, I am going to need a setup where every user has some derived/calculated information in the database. It should be maximum 100 different data sets with each around 100 rows (100x100) per user. These rows need to be refreshed around every three months. So, let's say with 10000 users if everybody uses all hundred places that would be 100M rows recreated every 3 months. As far as my knowledge the Postgre int field is 2147483647, that is 2100M+. So, am I going to run out of id/pk in around 5 years with this setup?

Should I rethink my setup or is there a way around?

I am using Python 2.7.6, PostgreSQL server is 9.3 and Django 1.8.

Sunny Jangid
  • 578
  • 4
  • 19
Stefan
  • 828
  • 12
  • 24
  • Possible duplicate of [django id integer limit](https://stackoverflow.com/questions/12150973/django-id-integer-limit) – solarissmoke Oct 26 '17 at 05:58
  • 1
    Django (1.10 onwards) provides the [`BigAutoField`](https://docs.djangoproject.com/en/1.11/ref/models/fields/#bigautofield). You'd need to create subclass of the `models.Model`, overwrite the `id` field and then inherit from that. – Kendas Oct 26 '17 at 05:59
  • @Kendas: Good suggestion. So, at some point in time the db really has to use ids of multiple million in value? I hoped for some auto-reindex or soemthing like that, before it gets to the crazy numbers ... :-) – Stefan Oct 26 '17 at 06:04
  • @Kendas: If you want repost your comment as an answer I accept that, it provides me with more specific info on how to modify my project. – Stefan Oct 26 '17 at 06:07
  • Unfortunately, no, it just keeps growing. – Kendas Oct 26 '17 at 06:07

1 Answers1

3

My first instinct was to use the BigAutoField, but that does not exist in Django 1.8. In any case, you'd use it like so:

from django.db import models

class CustomIDModel(models.Model):
    id = models.BigAutoField(primary_key=True)

class SomeModel(CustomIDModel):
    some_field = model.BooleanField()
    # More

Django 1.8 does have the UUIDField, however. This is larger but should do the trick.

import uuid
from django.db import models

class CustomIDModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

class SomeModel(CustomIDModel):
    some_field = model.BooleanField()
    # More
Kendas
  • 1,963
  • 13
  • 20