解决使用manage.py task迁移数据库时遇到的问题:django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

问题一

在使用manage.py 执行 makemigrations 迁移数据库的时候,遇到的问题如下

  File "E:\virtual_workshop\auto-test-platform-NGrddHeT\lib\site-packages\django\apps\registry.py", line 141, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

解决办法

在manage.py中加入一行代码

    django.setup()

问题二

继续执行 makegirations 发现报另一个错误

django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

解决办法

使用python manage.py makegirations进行迁移

posted @ 2022-04-27 23:05  cnhkzyy  阅读(177)  评论(0编辑  收藏  举报