在使用manage.py task迁移数据库时,如何处理django.core.exceptions.AppRegistryNotReady错误?

2026-05-21 20:571阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计231个文字,预计阅读时间需要1分钟。

在使用manage.py task迁移数据库时,如何处理django.core.exceptions.AppRegistryNotReady错误?

在使用 `manage.py` 执行 `makemigrations` 和迁移数据库时,遇到了以下问题:

在使用manage.py task迁移数据库时,如何处理django.core.exceptions.AppRegistryNotReady错误?

错误信息显示:File E:\virtual_workshop\auto-test-platform-NGrddHeT\lib\site-packages\django\apps\registry.py, line 141, in check_models_ready raise Ap

请检查 `registry.py` 文件的第 141 行,可能存在异常。

问题一

在使用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​​​进行迁移


本文共计231个文字,预计阅读时间需要1分钟。

在使用manage.py task迁移数据库时,如何处理django.core.exceptions.AppRegistryNotReady错误?

在使用 `manage.py` 执行 `makemigrations` 和迁移数据库时,遇到了以下问题:

在使用manage.py task迁移数据库时,如何处理django.core.exceptions.AppRegistryNotReady错误?

错误信息显示:File E:\virtual_workshop\auto-test-platform-NGrddHeT\lib\site-packages\django\apps\registry.py, line 141, in check_models_ready raise Ap

请检查 `registry.py` 文件的第 141 行,可能存在异常。

问题一

在使用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​​​进行迁移