Django Upgrading to 1.9 Error "Appregistrynotready: Apps Aren't Loaded Yet."

Django upgrading to 1.9 error AppRegistryNotReady: Apps aren't loaded yet.

I'd a custom function written on one of my models __init__.py file. It was causing the error. When I moved this function from __init__.py it worked.

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

registering signals in Django results in Apps aren't loaded yet. error

Try to include signals in AppConfig.ready method.

from django.apps import AppConfig

class MyAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'my_project.my_app'

def ready(self):
import my_project.my_app.signals

From docs on AppConfig.ready

Subclasses can override this method to perform initialization tasks such as registering signals. It is called as soon as the registry is fully populated.

If you’re registering model signals, you can refer to the sender by its string label instead of using the model class itself.

So, I suppose it's a common approach to include signals in AppConfig.ready method.



Related Topics



Leave a reply



Submit