Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I was stuck with the process when I wanted to deploy django project on server today. When I run python manage.py runserver on server, the terminal shows me this:

Traceback (most recent call last):   File "manage.py", line 10, in <module>     execute_from_command_line(sys.argv)   File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line     utility.execute()   File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 343, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 177, in fetch_command     commands = get_commands()   File "/usr/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper     result = user_function(*args, **kwds)   File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 72, in get_commands     for app_config in reversed(list(apps.get_app_configs())):   File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs     self.check_apps_ready()   File "/usr/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. 

The django version on the server is 1.8.5, and the local is 1.8.1. I doubt the version may cause this problem. But I also doubted the wsgi.py wasn't written properly, here's the wsgi.py:

import os import sys  path = '/Users/Peterhon/Desktop/dict/' if path not in sys.path:     sys.path.append(path)  os.chdir(path)  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")  import django django.setup()  from django.core.wsgi import get_wsgi_application application = get_wsgi_application() 

Here's the manage.py file:

#!/usr/bin/env python import os import sys  if __name__ == "__main__":     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")      from django.core.management import execute_from_command_line      execute_from_command_line(sys.arg) 

When I run python manage.py check on server, the output is below:

#!/usr/bin/env python import os import sys  if __name__ == "__main__":     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dict.settings")      from django.core.management import execute_from_command_line      execute_from_command_line(sys.argv) 

Could anyone give me some tips? Thanks too much

like image 353
Peter Tsung Avatar asked Oct 17 '15 12:10

Peter Tsung


People also ask

What is appregistrynotready in Django?

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. This generally happens when your app gets imported before the complete settings files are imported (i.e. before the initialization of INSTALLED_APPS). So make sure you don't have any code in settings file, which imports code from some other apps.

Why am I getting appregistrynotready exceptions?

Apps that can't be imported for any reason will also raise an AppRegistryNotReady exception. Here's the bug history for this issue. Additionally, trying to import something from the app level into the project level can cause this issue, too. For example, I'm currently working on project using Celery Beat.

What are the exceptions of Django core?

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.

Is non_app a Django app?

Update: The file "framework_prodcut_processing.py" runs without any errors when I move it to a non_app python directory. non_app is not a Django app. Show activity on this post. When you run commands like python manage.py runserver, django automatically runs django.setup for you using DJANGO_SETTINGS_MODULE environment variable.


2 Answers

This could well be an issue with your Django settings. For example, I just had specified in LOGGING a filename in a non-existent directory. As soon as I changed it to an existing directory, the issue was resolved.

like image 98
jbasko Avatar answered Sep 18 '22 22:09

jbasko


I ran into this issue today. There was an app in INSTALLED_APPS that didn't exist. Once it was removed, it resolved the exception. Apps that can't be imported for any reason will also raise an AppRegistryNotReady exception.

Here's the bug history for this issue.

Additionally, trying to import something from the app level into the project level can cause this issue, too. For example, I'm currently working on project using Celery Beat. I tried defining task schedules at the app level as dictionaries which were then imported to the celery.py file of the project. Importing the dictionary from the app into the project caused Django to throw an AppRegistryNotReady exception. Likewise, importing items between apps can cause the exception.

like image 27
infosmith Avatar answered Sep 22 '22 22:09

infosmith