0

Today my django app jumped from id 126 to 1125 in one of my models, 999 ids! Does anybody knows what could cause it?

See below the screenshot of my admin area, from my MSSQL database and also my model code: I appreciate any feedback that might help me to understand why django did it...

DJANGO ADMIN:

enter image description here

MSSQL:

enter image description here

MY MODEL: (which is working for many months without issues... Also, as you can see, the id is an AutoField, it is not in my class, only on the migrations file.)

class New_ticket(models.Model):
    process_expert = models.ForeignKey(Team_Structure, on_delete=models.SET_NULL, limit_choices_to={'available':True}, blank=True, null=True)
    status = models.ForeignKey(Status_table, on_delete=models.CASCADE, limit_choices_to={'available':True}, blank=True, null=True)
    created_by = models.CharField(max_length=20)
    created_on = models.DateTimeField()
    option = models.ForeignKey(Options_table, on_delete=models.CASCADE, limit_choices_to={'available':True}, verbose_name="Where is the issue?")
    priority_level = models.ForeignKey(Priority_level, on_delete=models.CASCADE, limit_choices_to={'available':True})
    department = models.ForeignKey(Department, on_delete=models.CASCADE, limit_choices_to={'available':True})
    transaction = models.CharField(max_length=50, blank=True)
    zone = ChainedForeignKey(Zone,chained_field="option",chained_model_field="option", show_all=False, auto_choose=True, sort=True, blank=True, null=True)
    duration_of_error = models.CharField(max_length=50, blank=True)
    error_message = models.TextField(max_length=250)
    comments = models.TextField(blank=True)
    upload_1 = models.FileField(upload_to='uploads/', blank=True, validators=[file_size])
    upload_2 = models.FileField(upload_to='uploads/', blank=True, validators=[file_size])
    upload_3 = models.FileField(upload_to='uploads/', blank=True, validators=[file_size])
    history = HistoricalRecords()

    def __str__(self):
        return str(self.id)

    class Meta:
        verbose_name_plural = "Tickets"
Thiago Araujo
  • 149
  • 2
  • 14
  • 1
    Is it really a concern? The only guarantee about an auto-generated ID is that it has to be unique - there's no real guarantee that it'll always be consecutive. It's also possible that if lots of transactions are occurring at the same time, it's not uncommon for a DB to allocate a "pool" of IDs, and if something happens and it thinks it can't allocate a unique one, then it'll just "discard that entire range"... and get a new pool of 'em ready for use. (so in short nothing to do with Django - just what MSSQL has done). – Jon Clements Mar 09 '20 at 15:46
  • 1
    @IvanStarostin looks like a nice find to me... – Jon Clements Mar 09 '20 at 15:49
  • Thanks guys, even my application is not affected, it is always good to understand the reason. Thanks for the feedback. – Thiago Araujo Mar 09 '20 at 17:18

0 Answers0