为什么我的 Django 迁移会加载我的 urls.py?
Why are my Django migrations loading my urls.py?
我正在尝试 运行 在新安装的 Heroku 实例上进行 django 迁移,但得到的是 ProgrammingError
。该错误是由于一些模块级查询在一个完全独立的模块中执行,在迁移过程中根本不应调用。
事实证明,它们文件被调用的原因是因为它们位于导入到我的 urls.py
中的文件中,并且出于某种原因,Django 正在加载这些 url。
Django 是否有某些原因必须加载 url,即使迁移不依赖于它们,是否有任何方法可以防止它们被加载?
BaseCommand class called requires_system_checks
, which is True
by default. It will check all potential problems prior to executing the command. In the 3.0 version, there is a flag called --skip-checks 中有一个布尔值 class 属性,它会跳过 运行 命令之前的 运行 系统检查。我检查了一个全新生成的 Django 项目,它没有引发我在 urls.py
模块中故意编写的预期异常。
我在 models.py
文件的顶部添加了以下行。
from django.core.management.base import BaseCommand
BaseCommand.requires_system_checks = False
我正在尝试 运行 在新安装的 Heroku 实例上进行 django 迁移,但得到的是 ProgrammingError
。该错误是由于一些模块级查询在一个完全独立的模块中执行,在迁移过程中根本不应调用。
事实证明,它们文件被调用的原因是因为它们位于导入到我的 urls.py
中的文件中,并且出于某种原因,Django 正在加载这些 url。
Django 是否有某些原因必须加载 url,即使迁移不依赖于它们,是否有任何方法可以防止它们被加载?
BaseCommand class called requires_system_checks
, which is True
by default. It will check all potential problems prior to executing the command. In the 3.0 version, there is a flag called --skip-checks 中有一个布尔值 class 属性,它会跳过 运行 命令之前的 运行 系统检查。我检查了一个全新生成的 Django 项目,它没有引发我在 urls.py
模块中故意编写的预期异常。
我在 models.py
文件的顶部添加了以下行。
from django.core.management.base import BaseCommand
BaseCommand.requires_system_checks = False