Hahaha ... I like how that ended, Russ :D Kind regards, Lloyd
On Sat, Apr 4, 2015 at 12:57 AM, Russell Keith-Magee < russ...@keith-magee.com> wrote: > > On Sat, Apr 4, 2015 at 6:25 AM, Mike <jterveh...@gmail.com> wrote: > >> Hi, >> Is there risk of getting too big PK value while adding and deleting rows >> for long time in same table? >> -Mike >> > > It depends on what you mean. > > This code: > > while True: > obj = MyObject.objects.create() > obj.delete() > > won't pose any problem at all. The primary key for each obj will > *generally* increase with each new object that is created - but it's not > *guaranteed* to increase. After a while, old, lower primary key values will > be re-allocated to new objects. Exactly how and when this is done depends > on the database. In short - don't assume that an object A created after > object B will have a higher primary key value. > > However, if you remove the "obj.delete()" line, and you just keep creating > new objects, you will *eventually* run out of available primary keys. When > this happens will depend on what data type your primary key has. PostgreSQL > and MySQL both default to 32 bit primary keys, so that means you can create > over 2 billion objects before you run out. If this isn't enough, you can > make your primary key a BIGINT, which will give a limit of 9 quintillion > objects. If that's not enough... well... you need to stop creating a > database row for every grain of sand on the beach :-) > > Yours, > Russ Magee %-) > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAJxq84-f1ORXSOF6i%3DW7AZVuMqRe_4S9G1ZxA%3DnxP-D8q%3DSA1g%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAJxq84-f1ORXSOF6i%3DW7AZVuMqRe_4S9G1ZxA%3DnxP-D8q%3DSA1g%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Regards, Sithu Lloyd Dube -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAH-SnCBPh_JKD8Dov3nm6Q4Kg%2BieZ%2BL7Ja3EmfgFHFrKb9iKfg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.