Django (& Pinax):回溯 "AppRegistryNotReady: Apps aren't loaded yet." 异常
Django (& Pinax): Tracing back "AppRegistryNotReady: Apps aren't loaded yet." exception
我正在使用 Django 1.7.5,并尝试构建 pinax-project-teams 启动器。当 运行ning python manage.py check
时,我遇到了“django.core.exceptions.AppRegistryNotReady:应用程序尚未加载。”。
我已经在 Whosebug 和其他地方通读过无数类似的错误,似乎这个错误是由多种原因引起的,并且往往涉及非常具体的特定情况修复。所以我可以预先删除几个解决方案:1)这是不是从以前的Django版本升级;和 2) 因此,wsgi.py
正确使用了较新的 from django.core.wsgi import get_wsgi_application
.
完整堆栈跟踪:
(env)trevor@nikola:webapp.git$ python manage.py check
Traceback (most recent call last):
File "manage.py", line 9, in <module>
startup.run()
File "/Users/trevor/zenith/webapp.git/djangoapp/startup.py", line 22, in run
admin.autodiscover()
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 23, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/usr/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 67, in autodiscover_modules
for app_config in apps.get_app_configs():
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/usr/local/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.
错误源于 pinax 的 startup.run()
,它由两个调用组成:autoload(["receivers"])
加载 settings.INSTALLED_APPS
中的模块,以及 admin.autodiscover()
。这是自动加载:
def autoload(submodules):
for app in settings.INSTALLED_APPS:
mod = import_module(app)
# print('Module: \t\n%s' % str(mod))
for submodule in submodules:
# print('Submodule: \t\n%s\n' % str(submodule))
try:
import_module("{0}.{1}".format(app, submodule))
except:
if module_has_submodule(mod, submodule):
raise
这经过 INSTALLED_APPS
并成功导入 所有 列出的应用程序,但紧接着 admin.autodiscover()
抛出 Apps aren't loaded yet.
消息。我不确定我错过了什么......很可能是显而易见的事情!
哦,最后:我已经阅读了 import django; django.setup()
修复程序,但我认为这是针对脚本和交互的,而不是 django 项目?因为我试过运行ning interactive,导入我的项目设置,运行 configure(),运行 django.setup(),然后退出,但这对当我尝试执行 运行server 时出现上述问题... :-/ 有什么想法吗?
编辑 - 更新和总结:
pinax-project-teams 代码与 Django 1.7 不完全兼容,至少在初始 "raw" 安装新 Django 项目时不兼容。解决方法包括几个步骤:
- 从
startup.py
(line 21, in run()
) 移除 explicit/redundant 应用加载:注释掉或删除 admin.autodiscover()
.
- 显式安装 Django 1.6.5 (
pip install Django==1.6.5
).
- 通过 django 1.6 版本同步数据库 (
python manage.py syncdb
)。
- 显式安装 Django 1.7.5 (
pip install Django==1.7.5
)。
原答案Post:
我想我已经缩小了一点,如果不是在范围内,至少是在根本原因上。虽然我的项目不是从 Django <=1.6 升级到 1.7,但这仍然是一个问题。 pinax-project-team 中的某些内容使其在默认情况下与 Django 1.7 不兼容。相同的安装将允许 syncdb
然后 runserver
在 1.6.5 django 安装上,但 django-1.7.5 抛出 Apps aren't loaded yet
.
我找到了一个很长的 Django 1.7 release notes 列表,我正在开始查看是否可以确定不兼容的原因。
至少有一个问题是 Pinax 在 startup.py
中的 "extra" 自动发现,as of 1.7 release is automatically executed 在 Django 自己的启动过程中。这似乎解决了应用程序加载问题……但 django.contrib.sites
中还有另一个问题。当 1.7 中的 运行 migrate
时,其中一个迁移由于数据库中缺少 table 而失败,特别是 django_site
(下面的完整跟踪)。这个 table 确实 存在于 1.6 django 安装的数据库中。修改 1.7 的设置以指向 1.6 项目中的 sqlite 文件解决了这个问题,瞧,它起作用了。所以这是我在 pinax-project-teams 和 Django 1.7 之间发现的仅有的两个冲突。
(env)trevor@nikola:mysite7$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: wiki, account, eventlog, kaleo, profiles, easy_thumbnails, pinax_theme_bootstrap, teams, bootstrapform
Apply all migrations: admin, contenttypes, sites, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 128, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 298, in sync_apps
call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=connection.alias, skip_validation=True, app_label=app_label, hide_empty=True)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
return klass.execute(*args, **defaults)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 61, in handle
self.loaddata(fixture_labels)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 91, in loaddata
self.load_label(fixture_label)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 148, in load_label
obj.save(using=self.using)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/serializers/base.py", line 173, in save
models.Model.save_base(self.object, using=using, raw=True)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/base.py", line 679, in _save_table
forced_update)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/base.py", line 723, in _do_update
return filtered._update(values) > 0
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/query.py", line 600, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1004, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: Problem installing fixture '/Users/trevor/code/pinax/7-pinaxtest/mysite7/fixtures/initial_data.json': Could not load sites.Site(pk=1): no such table: django_site
postgresql 和其他数据库的区别很重要。如果您使用的是 SQLite 后端,那将允许您只复制数据库文件本身以便在多个位置重复使用。然后你可以有一个1.6项目和一个1.7项目,报告同一个文件而不需要一直升级and/or降级
我正在使用 Django 1.7.5,并尝试构建 pinax-project-teams 启动器。当 运行ning python manage.py check
时,我遇到了“django.core.exceptions.AppRegistryNotReady:应用程序尚未加载。”。
我已经在 Whosebug 和其他地方通读过无数类似的错误,似乎这个错误是由多种原因引起的,并且往往涉及非常具体的特定情况修复。所以我可以预先删除几个解决方案:1)这是不是从以前的Django版本升级;和 2) 因此,wsgi.py
正确使用了较新的 from django.core.wsgi import get_wsgi_application
.
完整堆栈跟踪:
(env)trevor@nikola:webapp.git$ python manage.py check
Traceback (most recent call last):
File "manage.py", line 9, in <module>
startup.run()
File "/Users/trevor/zenith/webapp.git/djangoapp/startup.py", line 22, in run
admin.autodiscover()
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 23, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/usr/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 67, in autodiscover_modules
for app_config in apps.get_app_configs():
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/usr/local/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.
错误源于 pinax 的 startup.run()
,它由两个调用组成:autoload(["receivers"])
加载 settings.INSTALLED_APPS
中的模块,以及 admin.autodiscover()
。这是自动加载:
def autoload(submodules):
for app in settings.INSTALLED_APPS:
mod = import_module(app)
# print('Module: \t\n%s' % str(mod))
for submodule in submodules:
# print('Submodule: \t\n%s\n' % str(submodule))
try:
import_module("{0}.{1}".format(app, submodule))
except:
if module_has_submodule(mod, submodule):
raise
这经过 INSTALLED_APPS
并成功导入 所有 列出的应用程序,但紧接着 admin.autodiscover()
抛出 Apps aren't loaded yet.
消息。我不确定我错过了什么......很可能是显而易见的事情!
哦,最后:我已经阅读了 import django; django.setup()
修复程序,但我认为这是针对脚本和交互的,而不是 django 项目?因为我试过运行ning interactive,导入我的项目设置,运行 configure(),运行 django.setup(),然后退出,但这对当我尝试执行 运行server 时出现上述问题... :-/ 有什么想法吗?
编辑 - 更新和总结: pinax-project-teams 代码与 Django 1.7 不完全兼容,至少在初始 "raw" 安装新 Django 项目时不兼容。解决方法包括几个步骤:
- 从
startup.py
(line 21, inrun()
) 移除 explicit/redundant 应用加载:注释掉或删除admin.autodiscover()
. - 显式安装 Django 1.6.5 (
pip install Django==1.6.5
). - 通过 django 1.6 版本同步数据库 (
python manage.py syncdb
)。 - 显式安装 Django 1.7.5 (
pip install Django==1.7.5
)。
原答案Post:
我想我已经缩小了一点,如果不是在范围内,至少是在根本原因上。虽然我的项目不是从 Django <=1.6 升级到 1.7,但这仍然是一个问题。 pinax-project-team 中的某些内容使其在默认情况下与 Django 1.7 不兼容。相同的安装将允许 syncdb
然后 runserver
在 1.6.5 django 安装上,但 django-1.7.5 抛出 Apps aren't loaded yet
.
我找到了一个很长的 Django 1.7 release notes 列表,我正在开始查看是否可以确定不兼容的原因。
至少有一个问题是 Pinax 在 startup.py
中的 "extra" 自动发现,as of 1.7 release is automatically executed 在 Django 自己的启动过程中。这似乎解决了应用程序加载问题……但 django.contrib.sites
中还有另一个问题。当 1.7 中的 运行 migrate
时,其中一个迁移由于数据库中缺少 table 而失败,特别是 django_site
(下面的完整跟踪)。这个 table 确实 存在于 1.6 django 安装的数据库中。修改 1.7 的设置以指向 1.6 项目中的 sqlite 文件解决了这个问题,瞧,它起作用了。所以这是我在 pinax-project-teams 和 Django 1.7 之间发现的仅有的两个冲突。
(env)trevor@nikola:mysite7$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: wiki, account, eventlog, kaleo, profiles, easy_thumbnails, pinax_theme_bootstrap, teams, bootstrapform
Apply all migrations: admin, contenttypes, sites, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 128, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 298, in sync_apps
call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=connection.alias, skip_validation=True, app_label=app_label, hide_empty=True)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
return klass.execute(*args, **defaults)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 61, in handle
self.loaddata(fixture_labels)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 91, in loaddata
self.load_label(fixture_label)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 148, in load_label
obj.save(using=self.using)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/core/serializers/base.py", line 173, in save
models.Model.save_base(self.object, using=using, raw=True)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/base.py", line 679, in _save_table
forced_update)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/base.py", line 723, in _do_update
return filtered._update(values) > 0
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/query.py", line 600, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1004, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/trevor/code/pinax/7-pinaxtest/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: Problem installing fixture '/Users/trevor/code/pinax/7-pinaxtest/mysite7/fixtures/initial_data.json': Could not load sites.Site(pk=1): no such table: django_site
postgresql 和其他数据库的区别很重要。如果您使用的是 SQLite 后端,那将允许您只复制数据库文件本身以便在多个位置重复使用。然后你可以有一个1.6项目和一个1.7项目,报告同一个文件而不需要一直升级and/or降级