Erreur de mise à niveau de Django 1.7: AppRegistryNotReady: les applications ne sont pas encore chargées

J’essaie de mettre à niveau un projet de Django 1.6 à 1.7. Je reçois l’erreur suivante:

[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] mod_wsgi (pid=14523): Exception occurred processing WSGI script '/home/users1/k/kisvadim/domains/mathtasks.org/django.wsgi'. [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] Traceback (most recent call last): [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__ [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] response = self.get_response(request) [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 239, in handle_uncaught_exception [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] if resolver.urlconf_module is None: [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 361, in urlconf_module [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] self._urlconf_module = import_module(self.urlconf_name) [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] __import__(name) [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/mathtasks/urls.py", line 11, in  [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] admin.autodiscover() [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/consortingb/admin/__init__.py", line 23, in autodiscover [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] autodiscover_modules('admin', register_to=site) [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/utils/module_loading.py", line 67, in autodiscover_modules [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] for app_config in apps.get_app_configs(): [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] self.check_apps_ready() [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] raise AppRegistryNotReady("Apps aren't loaded yet.") [Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] AppRegistryNotReady: Apps aren't loaded yet. 

django.wsgi:

 import os, sys import django virtual_env = os.path.expanduser('~/virtualenv/PythonEnv') activate_this = os.path.join(virtual_env, 'bin/activate_this.py') execfile(activate_this, dict(__file__=activate_this)) sys.path.insert(0, os.path.join(os.path.expanduser('~'), 'django/mathtasks')) os.environ['DJANGO_SETTINGS_MODULE'] = 'mathtasks.settings' django.setup() import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

Des idées sur ce qui pourrait être à l’origine de l’erreur et comment y remédier?

UPDATE1:

J’ai remplacé:

 from django.consortingb.auth.models import User 

à:

 from django.conf import settings User = settings.AUTH_USER_MODEL 

Et j’obtiens l’erreur suivante:

 [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] mod_wsgi (pid=17128): Exception occurred processing WSGI script '/home/users1/k/kisvadim/domains/mathtasks.org/django.wsgi'. [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] Traceback (most recent call last): [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__ [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] response = self.get_response(request) [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 239, in handle_uncaught_exception [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] if resolver.urlconf_module is None: [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 361, in urlconf_module [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] self._urlconf_module = import_module(self.urlconf_name) [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] __import__(name) [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/mathtasks/urls.py", line 6, in  [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from utils.views import SniptRegistrationView [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/utils/views.py", line 1, in  [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from registration.backends.default.views import RegistrationView [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/backends/default/views.py", line 7, in  [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from registration.views import ActivationView as BaseActivationView [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/views.py", line 11, in  [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from registration.forms import RegistrationForm [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/forms.py", line 159, in  [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] class UserProfileForm(forms.ModelForm): [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/forms/models.py", line 284, in __new__ [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] opts.help_texts, opts.error_messages) [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/forms/models.py", line 184, in fields_for_model [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] opts = model._meta [Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] AtsortingbuteError: 'str' object has no atsortingbute '_meta' 

MISE À JOUR 2:

J’ai remplacé:

 from django.consortingb.auth.models import User 

à:

 from django.consortingb.auth import get_user_model User = get_user_model() 

et:

 models.ForeignKey(settings.AUTH_USER_MODEL) 

Et j’obtiens l’erreur suivante:

 [Thu Oct 09 16:10:52 2014] [error] No handlers could be found for logger "django.request" [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] mod_wsgi (pid=31421): Exception occurred processing WSGI script '/home/users1/k/kisvadim/domains/mathtasks.org/django.wsgi'. [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] Traceback (most recent call last): [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__ [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] response = self.get_response(request) [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 239, in handle_uncaught_exception [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] if resolver.urlconf_module is None: [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 361, in urlconf_module [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] self._urlconf_module = import_module(self.urlconf_name) [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] __import__(name) [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/mathtasks/urls.py", line 6, in  [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] from utils.views import SniptRegistrationView [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/utils/views.py", line 1, in  [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] from registration.backends.default.views import RegistrationView [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/backends/default/views.py", line 6, in  [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] from registration.models import RegistrationProfile [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/models.py", line 9, in  [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] User = get_user_model() [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/consortingb/auth/__init__.py", line 136, in get_user_model [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] return django_apps.get_model(settings.AUTH_USER_MODEL) [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 199, in get_model [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] self.check_models_ready() [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] raise AppRegistryNotReady("Models aren't loaded yet.") [Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] AppRegistryNotReady: Models aren't loaded yet. 

    J’ai eu une version similaire (la même?) Lors de la mise à niveau vers Django 1.7. Dans certains cas, il suffisait de mettre à jour le fichier wsgi: replace

     import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

    avec

     from django.core.wsgi import get_wsgi_application application = get_wsgi_application() 

    Je regardais à travers tous ces threads pour que le céleri fonctionne sur Windows (avec ce message d’erreur particulier) et je veux juste mettre l’accent sur

     import django django.setup() 

    En haut de votre fichier tasks.py, c’est finalement ce qui a fonctionné pour moi.

    INSTALLED_APPS Une virgule manquante dans le tableau, cela a causé l’erreur pour moi.

    J’ai eu cette erreur lorsque j’ai essayé d’importer des modèles à partir de __init__.py de l’application, ce qui n’est pas possible.

    Dans la configuration, le fichier d’application uwsgi (comme uwsgi.ini) remplace:

     module = django.core.handlers.wsgi:WSGIHandler() 

    sur

     module=django.core.wsgi:get_wsgi_application() 

    settings.AUTH_USER_MODEL est une chaîne (c’est pourquoi vous obtenez AtsortingbuteError: 'str' object has no atsortingbute '_meta' – il attend un modèle) et ne doit être utilisé que sur les déclarations ForeignKey :

     article de classe (modèles.Modèle):
         author = models.ForeignKey (settings.AUTH_USER_MODEL)
    

    Si vous voulez vous référer à votre modèle d’utilisateur ailleurs, vous devez utiliser get_user_model :

     à partir de django.consortingb.auth import get_user_model
    
     UserModel = get_user_model ()
    

    J’ai eu cette erreur en passant à un autre PC et en oubliant d’installer psycopg2 dans mon venv et en utilisant 'ENGINE': 'django.db.backends.postgresql', dans mes parameters.

    Peut-être que cela peut être utile à quelqu’un d’autre.

    Dans mon cas, j’ai oublié d’append une de mes sous-applications dans INSTALLED_APPS .

     INSTALLED_APPS = [ 'django.consortingb.admin', 'django.consortingb.auth', 'django.consortingb.contenttypes', 'django.consortingb.sessions', 'django.consortingb.messages', 'django.consortingb.staticfiles', 'basketball', 'basketball.area', 'basketball.game', 'basketball.player', ] 

    Dans mon cas, l’erreur a été provoquée par la mise à niveau de celery vers 4.x et cela dans mon INSTALLED_APPS: kombu.transport.django . Enlever ce qui a résolu le problème. Cela semble être dû principalement à une charge incorrecte de django lui-même.

    Dans mon cas SEcret_key a été commenté par erreur dans settings.py

    Il suffit de réinstaller Django en utilisant la ligne de commande, pas avec Pycharm.

    Cela pourrait être n’importe quelle raison. Dans mon cas, j’ai mis à jour ma version de python en dehors de mon environnement virtuel, mais mon virtualenv était toujours l’ancienne version, ce qui fait l’erreur. J’ai supprimé l’env et l’ai reconstruit à l’aide de la nouvelle version, et cela a fonctionné.