web-dev-qa-db-ja.com

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.
65
Vadim Kiselev

http://Django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts を参照してください

import Django
django.setup()
79
Aviah Laor

Django 1.7にアップグレードするときに、同様の(同じ?)問題がありました。場合によっては、wsgiファイルを更新するだけで十分でした:replace

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

from Django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
71
samirj

私はこれらのスレッドをすべて見て、セロリがウィンドウで動作するようにしました(この特定のエラーメッセージを使用)。

import Django
django.setup()

tasks.pyファイルの一番上に、これがついに機能しました。

17
HussienK

INSTALLED_APPS配列にコンマがないため、エラーが発生しました。

12
Mihkel L.

アプリの__init__.pyからモデルをインポートしようとしたときにこのエラーが発生しましたが、これは不可能です。

10
Mark

構成uwsgiアプリケーションファイル(uwsgi.iniなど)で以下を置き換えます。

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

オン

module=Django.core.wsgi:get_wsgi_application()
6
Dmitriy Yusupov

settings.AUTH_USER_MODELは文字列です(そのため、AttributeError: 'str' object has no attribute '_meta'を取得します-モデルが必要です)、ForeignKey宣言でのみ使用する必要があります。

 class Article(models.Model):
 author = models.ForeignKey(settings.AUTH_USER_MODEL)

ユーザーモデルを他の場所で参照する場合は、get_user_modelを使用する必要があります。

 Django.contrib.authからimport get_user_model 
 
 UserModel = get_user_model()
1
Serafeim

別のPCに移動して、psycopg2をvenvにインストールするのを忘れ、設定で'ENGINE': 'Django.db.backends.postgresql',を使用すると、このエラーが発生しました。

おそらく、それは他の誰かに役立つ可能性があります。

1
SaeX

私の場合、INSTALLED_APPS内にサブアプリケーションの1つを追加するのを忘れていました。

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',
]
0
matox

私の場合、セロリを4.xにアップグレードしたときにエラーが発生し、INSTALLED_APPSにkombu.transport.Djangoが含まれていました。これを削除することで問題は解決しました。 Django自体の何らかの不正確なロードが原因であるようです。

0
K.H.

私の場合、SEcret_keyがsettings.pyで誤ってコメントされました

0
EMT