from django.apps import AppConfig from django.db.utils import OperationalError, ProgrammingError from .models import ShopConfiguration class ConfigurationConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'configuration' def ready(self): """Ensure the ShopConfiguration singleton exists at startup. Wrapped in broad DB error handling so that commands like makemigrations/migrate don't fail when the table does not yet exist. """ try: ShopConfiguration.get_solo() except (OperationalError, ProgrammingError): ShopConfiguration.objects.create()