3

I'm creating an app in django that will eventually be filled with data from its predecessor. I'd like to have certain models start their auto-increment counter at 10000 to differentiate this data in advance and keep the pk accounting consistant. How can I do this in the model? AutoField doesn't seem to take parameters that would let me do this.

Chris Keele
  • 3,364
  • 3
  • 30
  • 52
  • I ended up creating a post_syncdb signal that checks for different database types(`if 'mysql' in connection.settings_dict['ENGINE']`) and handles resetting autoincrement for each table. The sqlite is one is pretty ugly, but there you have it. – Chris Keele Jul 02 '12 at 19:12

1 Answers1

2

This isn't a question about Django. AutoField is simply a representation of the underlying database's autoincrement property, and Django doesn't control it. Depending on your database backend, you might be able to reset the autoincrement start value: look at your db's documentation for details.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 1
    My hope was to be able to do this through the ORM, to keep out of backend-specifics. – Chris Keele Jul 02 '12 at 18:08
  • 4
    As Django has an ORM, e.g. a layer that abstracts the underlying database, it **is** a Django question. Unfortunately, the answer is "there's no built-in support for this". This question explains workarounds: http://stackoverflow.com/questions/117800/how-to-get-django-autofields-to-start-at-a-higher-number – Cerin Jun 26 '13 at 15:55