Error de actualización de Django 1.7: AppRegistryNotReady: las aplicaciones aún no están cargadas
django-1.7 (14)
En la configuración, el archivo de aplicación uwsgi (como uwsgi.ini) reemplaza:
module = django.core.handlers.wsgi:WSGIHandler()
en
module=django.core.wsgi:get_wsgi_application()
Estoy tratando de actualizar un proyecto de Django 1.6 a 1.7. Obtuve el siguiente error:
[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 <module>
[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/contrib/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()
¿Alguna idea de qué podría estar causando el error y cómo solucionarlo?
ACTUALIZACIÓN1:
Reemplacé:
from django.contrib.auth.models import User
a:
from django.conf import settings
User = settings.AUTH_USER_MODEL
Y me sale el siguiente error:
[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 <module>
[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 <module>
[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 <module>
[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 <module>
[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 <module>
[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] AttributeError: ''str'' object has no attribute ''_meta''
ACTUALIZACIÓN 2:
Reemplacé:
from django.contrib.auth.models import User
a:
from django.contrib.auth import get_user_model
User = get_user_model()
y:
models.ForeignKey(settings.AUTH_USER_MODEL)
Y me sale el siguiente error:
[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 <module>
[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 <module>
[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 <module>
[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 <module>
[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/contrib/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.
En mi caso, SEcret_key fue comentado por error en settings.py
En mi caso, el error fue causado cuando actualicé el apio a 4.xy tuve esto en mi INSTALLED_APPS:
kombu.transport.django
.
Eliminar eso resolvió el problema.
Parece que es causado principalmente por una carga incorrecta de django.
En mi caso, olvidé agregar una de mis sub-aplicaciones dentro de
INSTALLED_APPS
.
INSTALLED_APPS = [
''django.contrib.admin'',
''django.contrib.auth'',
''django.contrib.contenttypes'',
''django.contrib.sessions'',
''django.contrib.messages'',
''django.contrib.staticfiles'',
''basketball'',
''basketball.area'',
''basketball.game'',
''basketball.player'',
]
Estaba mirando a través de todos estos hilos para que el apio funcionara en Windows (con este mensaje de error en particular) y solo quiero enfatizar poner
import django
django.setup()
en la parte superior de su archivo task.py, esto es finalmente lo que lo hizo funcionar para mí.
Para aquellos (como yo) que reciben este error de shell:
Comprueba que estás ejecutando el shell de Django y no el de Python.
python manage.py shell
Podría ser cualquier motivo. En mi caso, actualicé mi versión de Python fuera de mi entorno virtual, pero mi virtualenv seguía siendo la versión anterior, lo que hace el error. Eliminé el env y lo volví a compilar usando la versión más nueva, y funcionó.
Recibí este error cuando intenté importar modelos desde la aplicación
__init__.py
, lo que no es posible.
Recibí este error cuando me mudé a una PC diferente y olvidé instalar
psycopg2
en mi venv y cuando utilicé
''ENGINE'': ''django.db.backends.postgresql'',
en mi configuración.
Quizás pueda ser útil para alguien más.
Simplemente reinstale Django usando la línea de comando, no en Pycharm me ayudó.
Tuve un problema similar (¿el mismo?) Al actualizar a Django 1.7. En mayo, fue suficiente para actualizar el archivo wsgi: reemplazar
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
con
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
ver http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts
import django
django.setup()
INSTALLED_APPS
Tenía una coma faltante en la matriz, lo que me causó el error.
settings.AUTH_USER_MODEL
es una cadena (es por eso que obtienes
AttributeError: ''str'' object has no attribute ''_meta''
- espera un Modelo) y solo debe usarse en declaraciones de
ForeignKey
:
class Article(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL)
Si desea consultar su modelo de usuario en otro lugar, debe usar
get_user_model
:
from django.contrib.auth import get_user_model UserModel = get_user_model()