我试图在PyCharm的Python控制台中导入我的模型之一,但出现以下错误
from damage.models import Damage
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2017.3.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\projects\django\deya\damage\models.py", line 2, in <module>
from django.contrib.auth.models import User
File "C:\Program Files\JetBrains\PyCharm 2017.3.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\projects\django\deya\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Program Files\JetBrains\PyCharm 2017.3.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\projects\django\deya\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\projects\django\deya\venv\lib\site-packages\django\db\models\base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\projects\django\deya\venv\lib\site-packages\django\apps\registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "C:\projects\django\deya\venv\lib\site-packages\django\apps\registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
我项目中的其他所有项目都正常运行。
我可以在运行时导入模型
python manage.py shell
从命令行甚至是PyCharm Terminal。
有人可以帮忙吗?
非常感谢
答案 0 :(得分:1)
不幸的是,我认为无法在Django
初始化之外使用python manage.py runserver
。当您在终端中运行此命令时,会发生什么错误?