# webapp/apps.py from django.apps import AppConfig from django.core.management import call_command from django.db.utils import OperationalError, ProgrammingError class WebappConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "webapp" def ready(self): """ Ensure the database cache table exists. This runs on startup in each process. If the table already exists or the DB isn't ready yet, we just ignore the error. """ try: call_command("createcachetable", "django_cache", verbosity=0) except (OperationalError, ProgrammingError): # Table already exists or DB not ready; safe to ignore pass except Exception: # Any other weird error: ignore as well, we just won't have DB cache pass