我想从1000开始在django模型上启动我的ID。我在Stackoverflow上发现了这个response但我在实现中遗漏了一些因为它无法正常工作。
这是我在apps.py
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from django.db import IntegrityError
from invoice.models import Invoice
def my_callback(sender, **kwargs):
if sender.name =="invoice":
try:
Invoice.objects.create(id=999)
Invoice.objects.delete()
except IntegrityError:
pass
class InvoiceConfig(AppConfig):
name = 'invoice'
def ready(self):
post_migrate.connect(my_callback, sender=self)
然后我确保migrate
发生,但模型继续从低数字增加。我错过了什么?