Skip to content
Advertisement

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

I am developing an app in Django.

I want to load data inside my model, that is glossary_entry, but the data is stored inside an xlsx file, that is dati_prova.xlsx.

In order to achieve this, I have developed the following script:

JavaScript

But when I run it from Anaconda prompt, I get

File “load_glossary.py”, line 7, in module …

raise AppRegistryNotReady(“Apps aren’t loaded yet.”) django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet.

What’s the problem?

Please note:

My app runs fine, just the uploading-data script fails.

Please note:

I copy pasted

JavaScript

from stack overflow answers because I was getting the error:

django.core.exceptions.ImproperlyConfigured: Requested setting USE_TZ, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

but I don’t have experience and I don’t understand what was the error.

Update

I have read on https://groups.google.com/forum/#!topic/django-users/bF_lRbzzguA that it could be that

The problem is that one of your applications imports models in its top-level init.py. This is not supported; for an explanation, you can read https://docs.djangoproject.com/en/1.9/ref/applications/#how-applications-are-loaded

Update

I changed the file as following:

JavaScript

And now I get:

RuntimeError: Model class myapp.models.mymodel doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.

But it is not true, since in settings.py I wrote my app name, and the project runs fine. Just the script does not work… It is like python cannot read my settings.py . What’s the problem? Maybe is it reading another set

Update

As suggested here https://stackoverflow.com/a/38821174/7658051
I have moved my script load_glossary.py into

myapp>management>commands


made a copy of my xlsx file into a csv one
and updated the code as follows:
JavaScript

And I am lunching it by typing into anaconda prompt

JavaScript

But then I get

line 20, in handle dataReader = csv.reader(open(csv_file), delimiter=’,’, quotechar='”‘) FileNotFoundError: [Errno 2] No such file or directory: ‘csv_file’

What’s wrong this time?

Advertisement

Answer

I solved the problem by substituting this:

JavaScript

with this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement