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

84 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER
class ModelTest(models.Model):
    tablename_id = models.AutoField(primary_key=True)

I hope I've helped.