Python Django 升级到 1.9 错误“AppRegistryNotReady:应用程序尚未加载。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34114427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:28:41  来源:igfitidea点击:

Django upgrading to 1.9 error "AppRegistryNotReady: Apps aren't loaded yet."

pythondjango

提问by Kishore K

When upgraded to django 1.9 from 1.8 I got this error. I checked answers for similar questions, but I didn't think this is an issue with any 3rd party packages or apps.

从 1.8 升级到 django 1.9 时,出现此错误。我检查了类似问题的答案,但我认为这不是任何 3rd 方软件包或应用程序的问题。

Traceback (most recent call last):
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
commands = get_commands()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
result = user_function(*args, **kwds)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
for app_config in reversed(list(apps.get_app_configs())):
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/home/kishore/.virtualenvs/andone/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.

I'd modified the Installed apps for 'django.contrib.auth'.

我修改了“django.contrib.auth”的已安装应用程序。

采纳答案by Kishore K

I'd a custom function written on one of my models __init__.pyfile. It was causing the error. When I moved this function from __init__.pyit worked.

我在我的模型__init__.py文件之一上编写了一个自定义函数。它导致了错误。当我从__init__.py它那里移出这个功能时。

回答by inlanger

Try to add this lines to the top of your settings file:

尝试将此行添加到设置文件的顶部:

import django
django.setup()

And if this will not help you try to remove third-party applications from your installed apps list one-by-one.

如果这对您没有帮助,请尝试从已安装的应用程序列表中一一删除第三方应用程序。

回答by pragmar

Try removing the entire settings.LOGGINGdictConfig and restart the server. If that works, rewrite the setting according to the v1.9 documentation.

尝试删除整个settings.LOGGINGdictConfig 并重新启动服务器。如果可行,请根据 v1.9 文档重写设置。

https://docs.djangoproject.com/en/1.9/topics/logging/#examples

https://docs.djangoproject.com/en/1.9/topics/logging/#examples

回答by algometrix

For me commenting out

为我注释掉

'grappelli.dashboard',
'grappelli',

in INSTALLED_APPS worked

在 INSTALLED_APPS 工作

回答by Anshik

My problem was: django-reversion>=1.8.7,<1.9

我的问题是:django-reversion>=1.8.7,<1.9

for django 1.9.7 you should use: django-reversion==1.10.0

对于 django 1.9.7,你应该使用:django-reversion==1.10.0

I were upgraded django-cms 3.2 to 3.3, and found it by commenting apps, then uncommenting back.

我将 django-cms 3.2 升级到 3.3,并通过评论应用程序找到它,然后取消评论。

Correct answer here: https://stackoverflow.com/a/34040556/2837890

正确答案在这里:https: //stackoverflow.com/a/34040556/2837890

回答by Amrit

This error may occur when you are adding an app in INSTALLED_APPSin the settings.pyfile but you do not have that app installed in your computer. You have two solution:

当您INSTALLED_APPSsettings.py文件中添加应用程序但您的计算机中没有安装该应用程序时,可能会发生此错误。你有两个解决方案:

  1. Installthat app using package managers like pipin ubuntu
  2. Or Comment out that installed app in the settings.pyfile
  1. Install该应用程序使用包管理器,例如pip在 ubuntu 中
  2. 或在settings.py文件中注释掉已安装的应用程序

This error may also arise if you are not in your virtual environmentwhich you may have created for your project.

如果您不在virtual environment为您的项目创建的项目中,也可能会出现此错误。

回答by Waykos

This issue is also observed for inconsistent settings.py for incorrectly writing INSTALLED_APPS, verify if you correctly included apps and separated with "," .

对于不一致的 settings.py 也会观察到此问题,因为它错误地编写了 INSTALLED_APPS,请验证您是否正确包含了应用程序并用 "," 分隔。

回答by xing liu

If your setting.py files fill are correct,you can try to arrive manage.py files proceed call danjgo.setup() in main method . Then run manage.py ,finally again run project ,the issue could disappear.

如果你的 setting.py 文件填写正确,你可以尝试到 manage.py 文件继续在 main 方法中调用 danjgo.setup() 。然后运行 ​​manage.py ,最后再次运行项目,问题可能会消失。

回答by Preetam

In the "admin" module of your app package, do register all the databases created in "models" module of the package.

在应用包的“admin”模块中,注册在包的“models”模块中创建的所有数据库。

Suppose you have a database class defined in "models" module as:

假设您在“models”模块中定义了一个数据库类:

class myDb1(models.Model):
    someField= models.Charfiled(max_length=100)

so you must register this in the admin module as:

所以你必须在管理模块中将其注册为:

from .models import myDb1
admin.site.register(myDb1)

I hope this resolve the error.

我希望这可以解决错误。

回答by Albyorix

For me, the problem came from the fact that I was importing an app in INSTALLED_APPSwhich was itself importing a model in its __init__.pyfile

对我来说,问题来自这样一个事实,即我正在导入一个应用程序,INSTALLED_APPS该应用程序本身在其__init__.py文件中导入一个模型

I had :

我有:

settings.py

settings.py

INSTALLED_APPS = [
    ...
    'myapp',
    ...
]

myapp.__init__.py

myapp.__init__.py

from django.contrib.sites.models import Site

commenting out import modelsin myapp.__init__.pymade it work :

注释掉import modelsmyapp.__init__.py做它的工作:

# from django.contrib.sites.models import Site