I have a self cache definition in my models and I want to clear old caches when server is restarting.
I use this code in settings.py after INSTALLED_APPS:
from cache.models import Cache
Cache.clear()
And in Cache/models.py:
class Cache(models.Model):
key = models.CharField("key", max_length=511, db_index=True)
data = models.TextField("data")
expiration = models.DateTimeField("expiration", db_index=True, null=True)
@staticmethod
def clear():
Cache.objects.all().delete()
But I get this error:
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.