How to Resolve Error Message django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet.

Posted on

Introduction

The following article has a specific content to discuss about how to resolve an error message. The error message is ‘Apps aren’t loaded yet.’ Actually, there is a connection with the previous article with the title of ‘How to Resolve Error Message export DJANGO_SETTINGS_MODULE=”app.settings” SyntaxError: invalid syntax’ in this link. The main purpose of that article is to import a class in the python command console or python command shell. The steps for importing the class is a failure with the error message as in the title. The following is the complete error of the output :

>>> from app.models import MyClass;
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/user/python/django/project/app/models.py", line 6, in 
    class Category(models.Model):
  File "/home/user/python/django/project/env/lib/python3.6/site-packages/django/db/models/base.py", line 103, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/user/python/django/project/env/lib/python3.6/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
    self.check_apps_ready()
  File "/home/user/python/django/project/env/lib/python3.6/site-packages/django/apps/registry.py", line 135, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
>>> 

The above error output appears after the following series of command execution. Those command execution exist as follows :

1. Activate the python virtual environment by executing the following command pattern as follows :

source env_folder/bin/activate

The execution of the above command pattern exist as in the following example :

user@hostname:~/python/django/project$ source env/bin
(env) user@hostname:~/python/django/project$

2. Next step, execute the following command to enter the python command console or the python command shell :

(env) user@hostname:~/python/django/project$ python
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

3. Continue on the step, execute the following command to define an environment variable with the name of ‘DJANGO_SETTINGS_MODULE’ :

>>> import os;
>>> os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings';

4. The error will suddenly after the above command execution when performing the following command :

>>> from app.models import MyClass;
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/user/python/django/project/app/models.py", line 6, in 
    class Category(models.Model):
  File "/home/user/python/django/project/env/lib/python3.6/site-packages/django/db/models/base.py", line 103, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/user/python/django/project/env/lib/python3.6/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
    self.check_apps_ready()
  File "/home/user/python/django/project/env/lib/python3.6/site-packages/django/apps/registry.py", line 135, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
>>> quit()

Solution

In order to solve the above error message, before executing the above command for importing the class, just execute the following command :

>>> import django;
>>> django.setup();
>>> from app.models import MyClass;
>>> 

Overall, to successfully import a class, the following is the complete steps as an output of the command execution :

(env) user@hostname:~/python/django/posting$ python
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os;
>>> os.environ['DJANGO_SETTINGS_MODULE'] = 'posting.settings';
>>> import django;
>>> django.setup();
>>> from app.models import MyClass;
>>> 

One thought on “How to Resolve Error Message django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet.

Leave a Reply