Django 1.7 Throws Django.Core.Exceptions.Appregistrynotready: Models Aren't Loaded Yet

Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

This is what solved it for us and these folks:

Our project started with Django 1.4, we went to 1.5 and then to 1.7. Our wsgi.py looked like this:

import os

from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = WSGIHandler()

When I updated to the 1.7 style WSGI handler:

import os

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()

Everything works now.

Django 1.7 upgrade error: AppRegistryNotReady: Models aren't loaded yet

The problem is with this line ("/Users/Name/Dev/tps/products/models.py", line 127):

watson.register(Product.objects.exclude(productimage=None))

You try to reference a model at the import time. It is no longer possible in Django 1.7. Django 1.7 allows you to use your models only after all of the applications are loaded. You should move this call to the ready callback of AppConfig, like this:

from django.apps import AppConfig

class ProductsConfig(AppConfig):
name = 'products'

def ready(self):
Product = self.get_model('Product')
watson.register(Product.objects.exclude(productimage=None))

Then you should reference this AppConfig in the __init__.py of your products app:

default_app_config = 'products.apps.ProductsConfig'

Where apps is the name of the module where you put the config.

Relevant Django doc: https://docs.djangoproject.com/en/dev/ref/applications/

Overall, because of this change, migrating to Django 1.7 is not as easy as one would like it to be. Here are some troubleshooting tips: https://docs.djangoproject.com/en/1.7/ref/applications/#troubleshooting

Django 1.8: django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

In short: change wsgi.py file on Ubuntu server located in /usr/django/engine.wsgi (where engine is your project name)

The problem was in settings in file wsgi.py: settings belong to django 1.6 version, but not for 1.8

I saw many answers on Stackoverflow how to solve but this didn't help me because i edited wsgi.py located in my project folder but this was wrong.

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

I solved this with properties at class level.

class MyModel(models.Model):

@classproperty
def special_foo(cls):
return Foo.objects.filter(name__contains='special')

Unfortunately python does not support @classproperty right out of the box yet.

I used the implementation from here https://stackoverflow.com/a/5191224/633961

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet when trying to load data into my model

I solved the problem by substituting this:

import pandas as pd
from django.conf import settings

settings.configure()

from myapp.models import glossary_entry #this is line 7

path=r"mypath\dati_prova.xlsx"

with open(path) as f:
reader = pd.read_excel(f)
next(reader, None) # skip the headers

for row in reader:
_, created = glossary_entry.objects.get_or_create(
Lemma = row[0],
Acronym = row[1],
Definizione = row[2],
)
# creates a tuple of the new object or
# current object and a boolean of if it was created

with this:

import pandas as pd
from myapp.models import glossary_entry

def pour_entire_entry_model():

elements = glossary_entry.objects.all()

for element in elements:

entry = acquired_terminology.objects.create()

entry.Lemma = element.Lemma
entry.Acronym = element.Acronym
entry.Definizione = element.Definizione

# creates a tuple of the new object or
# current object and a boolean of if it was created

While upgrading Django 1.5 to 1.7 throws “Models aren't loaded yet error

From the traceback I see the following:

  File "/home/venkat/sample-applications/wfmis-django-upgrade/wfmis-upgrade/django-pursuite/apps/admin/models/__init__.py", line 14, in <module>
from occupational_standard import *
File "/home/venkat/sample-applications/wfmis-django-upgrade/wfmis-upgrade/django-pursuite/apps/admin/models/occupational_standard.py", line 160, in <module>
admin.site.register(OccupationalStandard, OccupationalStandardAdmin)

There is a call to admin.site.register in the models. Registering models should happen in admin not in models.



Related Topics



Leave a reply



Submit