gpt4 book ai didi

python - django:将 tastypie 添加到已安装的应用程序后出现 AppRegistryNotReady 异常

转载 作者:太空宇宙 更新时间:2023-11-04 06:42:47 25 4
gpt4 key购买 nike

所以,我现在在 Django 1.7rc2 上运行,创建了几个模型,当我运行 ./manage.py shell 时,一切正常,但是,一旦我添加了 tastypie(我有最后一个稳定版本, 0.11.1) 到 INSTALLED_APPS,我在 ./manage.py shell 上遇到了这个异常

Traceback (most recent call last):
File "manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/miki/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/miki/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/miki/project/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/miki/project/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/miki/project/local/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/miki/project/local/lib/python2.7/site-packages/tastypie/models.py", line 31, in <module>
from tastypie.compat import AUTH_USER_MODEL
File "/home/miki/project/local/lib/python2.7/site-packages/tastypie/compat.py", line 13, in <module>
User = get_user_model()
File "/home/miki/project/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 136, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/home/miki/project/local/lib/python2.7/site-packages/django/apps/registry.py", line 199, in get_model
self.check_models_ready()
File "/home/miki/project/local/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

我用谷歌搜索了一下,只在脚本从独立脚本运行时遇到过这个异常,但事实并非如此。此外,在 django 文档中它说

Another common culprit is django.contrib.auth.get_user_model(). Use the AUTH_USER_MODEL setting to reference the User model at import time.

但是我在我的设置中设置了这些设置

# The model to use to represent a User.
AUTH_USER_MODEL = 'customuser.CustomUser'

错误是在我的代码中的某个地方还是在 tastypie 中?

最佳答案

提示的重点不仅在于您在设置中定义它,而且您应该将该设置用作任何指向用户的外键的目的地,而不是使用 get_user_model()。

关于python - django:将 tastypie 添加到已安装的应用程序后出现 AppRegistryNotReady 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25449782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com