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

2761 단어 overflow
How to get Django AutoFields to start at a higher number - Stack Overflow
1
down vote
 
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.

좋은 웹페이지 즐겨찾기