For our Django App, we\'d like to get an AutoField
to start at a number other than 1. There doesn\'t seem to be an obvious way to do this. Any ideas?
Here is what I did..
def update_auto_increment(value=5000, app_label="remrate_data"):
"""Update our increments"""
from django.db import connection, transaction, router
models = [m for m in get_models() if m._meta.app_label == app_label]
cursor = connection.cursor()
for model in models:
_router = settings.DATABASES[router.db_for_write(model)]['NAME']
alter_str = "ALTER table {}.{} AUTO_INCREMENT={}".format(
_router, model._meta.db_table, value)
cursor.execute(alter_str)
transaction.commit_unless_managed()