How to get Django AutoFields to start at a higher number Stack Overflow

How to get Django AutoFields to start at a higher number - Stack Overflow

For MySQL i created a signal that does this after syncdb:

from django.db.models.signals import post_syncdb
from project.app import models as app_models

def auto_increment_start(sender, **kwargs):
    from django.db import connection, transaction
    cursor = connection.cursor()
    cursor = cursor.execute("""
                                ALTER table app_table AUTO_INCREMENT=2000
                            """)
    transaction.commit_unless_managed()

post_syncdb.connect(auto_increment_start, sender=app_models)

After a syncdb the alter table statement is executed. This will exempt you from having to login into mysql and issuing it manually.

EDIT: I know this is an old thread, but I thought it might help someone.

原文地址:https://www.cnblogs.com/lexus/p/2483469.html