无法使用用户模型和信息模型导入模型名称 Django

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x105de5048>

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper

    fn(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run

    autoreload.raise_last_exception()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception

    raise _exception[1]

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute

    autoreload.check_errors(django.setup)()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper

    fn(*args, **kwargs)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate

    app_config.import_models()

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models

    self.models_module = import_module(models_module_name)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 994, in _gcd_import


我在最近的 django 应用程序中随机收到此错误。我不知道为什么。模型在我的项目中的其他应用程序/文件中导入。任何帮助表示赞赏。


至尊宝的传说
浏览 209回答 1
1回答

心有法竹

我相信您遇到了循环模型导入。似乎您将 User 导入到 seasons.model 中,将 Seasons 导入到 users.model 中。如果您将它们用作外键,则可以将其设置为:user&nbsp;=&nbsp;models.ForeignKey('users.User')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python