[python] Django upgrading to 1.9 error "AppRegistryNotReady: Apps aren't loaded yet."

When upgraded to django 1.9 from 1.8 I got this error. I checked answers for similar questions, but I didn't think this is an issue with any 3rd party packages or apps.

Traceback (most recent call last):
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
commands = get_commands()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
result = user_function(*args, **kwds)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
for app_config in reversed(list(apps.get_app_configs())):
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

I'd modified the Installed apps for 'django.contrib.auth'.

This question is related to python django

The answer is


This error may occur when you are adding an app in INSTALLED_APPS in the settings.py file but you do not have that app installed in your computer. You have two solution:

  1. Install that app using package managers like pip in ubuntu
  2. Or Comment out that installed app in the settings.py file

This error may also arise if you are not in your virtual environment which you may have created for your project.


My problem was: django-reversion>=1.8.7,<1.9

for django 1.9.7 you should use: django-reversion==1.10.0

I were upgraded django-cms 3.2 to 3.3, and found it by commenting apps, then uncommenting back.

Correct answer here: https://stackoverflow.com/a/34040556/2837890


This issue is also observed for inconsistent settings.py for incorrectly writing INSTALLED_APPS, verify if you correctly included apps and separated with "," .


I get that error when i try to run:

python manage.py makemigrations

i tried so many things and realized that i added some references to "settings.py" - "INSTALLED_APPS"

Just be sure what you write there is correct. My mistake was ".model." instead of ".app."

Corrected that mistake and it's working now.


Try to add this lines to the top of your settings file:

import django
django.setup()

And if this will not help you try to remove third-party applications from your installed apps list one-by-one.


In the "admin" module of your app package, do register all the databases created in "models" module of the package.

Suppose you have a database class defined in "models" module as:

class myDb1(models.Model):
    someField= models.Charfiled(max_length=100)

so you must register this in the admin module as:

from .models import myDb1
admin.site.register(myDb1)

I hope this resolve the error.


For me commenting out

'grappelli.dashboard',
'grappelli',

in INSTALLED_APPS worked


Got this error while trying to access model objects in apps.py:

class QuizConfig(AppConfig):
name = 'quiz'

def ready(self):
    print('===============> Django just started....')
    questions_by_category = Question.objects.filter(category=2) # <=== Guilty line of code.

Trying to access Question before the app has loaded the model class caused the error for me.


I get that error when I try to run test.py(not full scripts, I don't want to use python manage.py test)

and the following method is working for me.

import os
import django
if 'env setting':
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'YourRoot.settings')
    django.setup()
from django.test import TestCase
...

class SomeTest(TestCase):
    def test_one(self):  # <-- Now, I can run this function by PyCharm
        ...

    def test_two(self):
        ...

I put the User import into the settings file for managing the rest call token like this

# settings.py
from django.contrib.auth.models import User
def jwt_get_username_from_payload_handler(payload):
   ....

JWT_AUTH = {
    'JWT_PAYLOAD_GET_USERNAME_HANDLER': jwt_get_username_from_payload_handler,
    'JWT_PUBLIC_KEY': PUBLIC_KEY,
    'JWT_ALGORITHM': 'RS256',
    'JWT_AUDIENCE': API_IDENTIFIER,
    'JWT_ISSUER': JWT_ISSUER,
    'JWT_AUTH_HEADER_PREFIX': 'Bearer',
}
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
       'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
}

Because at that moment, Django libs are not ready yet. Therefore, I put the import inside the function and it started to work. The function needs to be called after the server is started


I tried tons of things, but only downgrading Django to 1.8.18 fixed this issue for me:

pip install django==1.8.18

It is one of the installed apps that is failing, but I could not find which one.


Try removing the entire settings.LOGGING dictConfig and restart the server. If that works, rewrite the setting according to the v1.9 documentation.

https://docs.djangoproject.com/en/1.9/topics/logging/#examples


When I change my django version to 1.9, it don't arise the error. pip uninstall django pip install django==1.9


Late to the party, but grappelli was the reason for my error as well. I looked up the compatible version on pypi and that fixed it for me.


In my case one of my settings, 'CORS_ORIGIN_WHITELIST' was set in the settings.py file but was not available in my .env file. So I'll suggest that you check your settings, especially those linked to .env


As others have said this can be caused when you've not installed an app that is listed in INSTALLED_APPS.

In my case, manage.py was attempting to log the exception, which led to an attempt to render it which failed due to the app not being initialized yet. By commenting out the except clause in manage.py the exception was displayed without special rendering, avoiding the confusing error.

# Temporarily commenting out the log statement.
#try:
    execute_from_command_line(sys.argv)
#except Exception as e:
#    log.error('Admin Command Error: %s', ' '.join(sys.argv), exc_info=sys.exc_info())
#    raise e

In my case, the error occurred when I made python manage.py makemigrations on Django 2.0.6.

The solution was to run python manage.py runserver and see the actual error (which was just a missing environment variable).


django.setup() in the top will not work while you are running a script explicitly. My problem solved when I added this in the bottom of the settings file

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
import sys
if BASE_DIR not in sys.path:
    sys.path.append(BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] =  "igp_lrpe.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "igp_lrpe.settings")
import django
django.setup()

My problem was that I tried to import a Django model before calling django.setup()

This worked for me:

import django
django.setup()

from myapp.models import MyModel

The above script is in the project root folder.


For me, the problem came from the fact that I was importing an app in INSTALLED_APPS which was itself importing a model in its __init__.py file

I had :

settings.py

INSTALLED_APPS = [
    ...
    'myapp',
    ...
]

myapp.__init__.py

from django.contrib.sites.models import Site

commenting out import models in myapp.__init__.py made it work :

# from django.contrib.sites.models import Site

Try activating the virtual env. In my case, using the git command line tool:

source scripts/activate

Solves my problem.



First import and run django.setup() before importing any models


All the above answers are good but there is a simple mistake a person could do is that (In fact in my case it was).

I imported Django model from my app before calling django.setup(). so proper way is to do...

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'first_project.settings')

import django
django.setup()

then any other import like

from faker import Faker
import random
# import models only after calling django.setup()
from first_app.models import Webpage, Topic, AccessRecord

If your setting.py files fill are correct,you can try to arrive manage.py files proceed call danjgo.setup() in main method . Then run manage.py ,finally again run project ,the issue could disappear.