from django.apps import AppConfig from django.db.utils import OperationalError, ProgrammingError class ConfigurationConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'configuration' def ready(self): """Ensure the SiteConfiguration 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: from .models import SiteConfiguration # local import to avoid premature app registry access SiteConfiguration.get_solo() # creates if missing except (OperationalError, ProgrammingError): # DB not ready (e.g., before initial migrate); ignore silently pass