Django 1.7 업그레이드 오류 : AppRegistryNotReady : 앱이 아직로드되지 않았습니다.
Django 1.6에서 1.7로 프로젝트를 업그레이드하려고합니다. 다음과 같은 오류가 발생합니다.
[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()
오류의 원인과 해결 방법에 대한 아이디어가 있습니까?
업데이트 1 :
나는 교체했다 :
from django.contrib.auth.models import User
에:
from django.conf import settings
User = settings.AUTH_USER_MODEL
그리고 다음과 같은 오류가 발생합니다.
[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'
업데이트 2 :
나는 교체했다 :
from django.contrib.auth.models import User
에:
from django.contrib.auth import get_user_model
User = get_user_model()
과:
models.ForeignKey(settings.AUTH_USER_MODEL)
그리고 다음과 같은 오류가 발생합니다.
[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.
참조 http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts를
import django
django.setup()
Django 1.7로 업그레이드 할 때 비슷한 문제가 발생했습니다. 경우에 따라 wsgi 파일을 업데이트하는 것으로 충분합니다.
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
와
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
나는 셀러리가 윈도우에서 작동하도록 (이 특정 오류 메시지와 함께)이 모든 스레드를 살펴보고 있었고
import django
django.setup()
tasks.py 파일의 맨 위에 마침내 이것이 저에게 효과가 있습니다.
INSTALLED_APPS
배열에 쉼표가 없어서 오류가 발생했습니다.
I got this error when I tried to import models from the app's __init__.py
, which is not possible.
In configuration uwsgi application file ( like uwsgi.ini ) replace:
module = django.core.handlers.wsgi:WSGIHandler()
on
module=django.core.wsgi:get_wsgi_application()
settings.AUTH_USER_MODEL
is a string (that's why you get AttributeError: 'str' object has no attribute '_meta'
- it expects a Model) and should be used only on ForeignKey
declarations:
class Article(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL)
If you want to refer to your user model somewhere else you need to use get_user_model
:
from django.contrib.auth import get_user_model UserModel = get_user_model()
I got this error when moving to a different PC and forgetting to install psycopg2
in my venv and when using 'ENGINE': 'django.db.backends.postgresql',
in my settings.
Perhaps it can be useful to someone else.
In my case, I forgot to add one of my sub-applications inside 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',
]
In my case the error was caused when I upgraded celery to 4.x and I had this in my INSTALLED_APPS: kombu.transport.django
. Removing that resolved the issue. Seems it is mostly caused by some incorrect load of django itself.
In my case SEcret_key was commented by mistake in settings.py
Just reinstall Django using the command line, not in Pycharm helped to me.
It could be any reason. In my case, I updated my python version outside of my virtual environment, but my virtualenv was still the old version, that makes the error. I deleted the env and build it again using the newer version, and it worked.
'code' 카테고리의 다른 글
JQuery는 클릭시 다중 선택 선택 상자의 모든 옵션을 선택합니다. (0) | 2020.11.16 |
---|---|
Visual Studio에서 단위 테스트의 실행 순서 제어 (0) | 2020.11.16 |
Zend_Db_Select로 WHERE IN 절을 만드는 방법 (0) | 2020.11.16 |
pdfminer를 라이브러리로 사용하는 방법 (0) | 2020.11.16 |
PhantomJS 인스턴스의 '풀'을 관리하는 방법 (0) | 2020.11.15 |