首页 > 解决方案 > Django:模型类 __main__.Source 在 PyCharm 中加载模型时未声明显式 app_label

问题描述

我以前在 PyCharm 中的 Python shell 中加载模型之前没有错误,但现在它通过了这个错误

Traceback (most recent call last):
  File "<input>", line 12, in <module>
  File "C:\...\lib\site-packages\django\db\models\base.py", line 112, in __new__
    raise RuntimeError(
RuntimeError: Model class __main__.Source doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

我检查了诸如thisthis之类的类似问题,并遵循了建议的答案,但没有成功。有趣的是,python manage.py runserver它不会通过任何错误和网站顺利加载。

我的环境的唯一变化是我昨天获得的 Windows 更新。

我已经为我的所有应用程序设置了应用程序名称,设置 DJANGO_SETTINGS_MODULE 并且所有导入都是绝对的。

标签: pythondjangopycharm

解决方案


推荐阅读