I would like to start my ids on a django model from 1000. I've found this response on Stackoverflow but I am missing something in my implementation because it is not working.
This is my code in 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)
I've then ensure migrate
takes place but the model continues to increment from low numbers. What am I missing?