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?
I know this question is old, but I'm posting this method for those who find this question in search results and need a good solution for more recent Django versions (i.e. Django >= 1.8):
Create a data migration as documented here. This solution will run when you migrate your app (and, probably, as part of your deployment strategy) and allows you to write code that caters to the specific needs of your database.
I consider this the cleanest method of setting an initial value for auto-incrementing database fields in Django >= 1.7 because it takes advantage of standard Django migrations and doesn't hijack other features of the framework in ways that may not work in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With