Search code examples
django-modelsauto-incrementfield-names

Is there a way to specify the name of the autoincrement id in Django?


How can I change the field name of Django's autoincrement from id to something like tablename_id?

I want to do it in the model definition itself.

The autoincrement key is created automatically do there doesn't seem a way to set it via the db_column attribute.


Solution

  • class ModelTest(models.Model):
        tablename_id = models.AutoField(primary_key=True)
    

    I hope I've helped.