from django.core.management.color import no_style from django.db import connection def sqlsequencereset(models, conn=connection): """ Update sequences of fields of `models`. This function should be called after manually assigning a value to an `AutoField`. https://docs.djangoproject.com/en/1.11/ref/databases/#manually-specifying-values-of-auto-incrementing-primary-keys """ sequence_sql = conn.ops.sequence_reset_sql(no_style(), models) if sequence_sql: with conn.cursor() as cursor: for line in sequence_sql: cursor.execute(line)