Search code examples
pythonmysqldjangomodels

set auto increment initial value for id in django model


i have a model with just one field. name.

class City(models.Model): <br>
    name = models.CharField(max_length=30)

Django sets id by itself so I end up with id and a description field in SQL.

but that id field is always increment by 1. I want to start it from 1000 and then increment by one.

Is there any way to do this in Django?


Solution

  • You could use initial data to give your models ids from 1000. I think if the first models PK is 1000 django will continue with 1001.

    Or you create a attribute called custom_id which is always 1000+id. This way you have an additional field in your DB but it will work.