8

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.

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?

I currently use PostgreSQL as my database.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
deadlock
  • 7,048
  • 14
  • 67
  • 115
  • 1
    Two solutions: [a] don't make primary keys integers. Having a string value with 50 spaces will be sufficient; or [b] this kind of data isn't suited well for relational databases; perhaps a graph db would be better. – Burhan Khalid Dec 10 '13 at 08:15

2 Answers2

12

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.

culix
  • 10,188
  • 6
  • 36
  • 52
RemcoGerlich
  • 30,470
  • 6
  • 61
  • 79
-3

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.

Thibault J
  • 4,336
  • 33
  • 44
  • 1
    check out RemcoGerlich's answer, thanks for trying to tackle the problem, appreciate it – deadlock Dec 10 '13 at 16:45
  • Isn't it 4294967295? Since **2^32 - 1**. https://stackoverflow.com/questions/5771520/why-is-the-maximum-value-of-an-unsigned-n-bit-integer-2%E2%81%BF-1-and-not-2%E2%81%BF – AnonymousUser Sep 02 '22 at 06:55