Django:运行自定义命令时跳过系统检查 [英] Django: skip system check when running custom command

查看:45
本文介绍了Django:运行自定义命令时跳过系统检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经向使用Django 1.6.11开发的应用程序添加了自定义管理命令.我们将此命令称为 initdb ,它执行一组特定的操作:

I've added a custom management command to an application developed using Django 1.6.11. This command, let's call it initdb, performs a set of particualr actions:

  • 检查是否存在settings.py中的数据库和用户,如果不存在,请设置适当的字符集,授予访问权限,等等.
  • 执行 syncdb
  • 加载特定的数据库转储

换句话说,对于从零开始的快速数据库初始化非常方便.

In other words, it's very handy for quick database initialization from total zero.

现在,我正在迁移到Django 1.8.5,我注意到的一件事是,在几乎所有命令之前,Django都会自动从新的系统检查框架执行 check 命令,其中包括东西检查数据库/用户表单 settings.py 是否存在.导致无法执行自定义命令的情况出现,因为自动检查会引发无法访问数据库的异常(实际上,我的自定义命令应该创建它).

Now, I'm migrating to Django 1.8.5 and one thing I've noticed is that, before almost every command, Django automatically executes check command from new system check framework, which among other stuff checks if database/user form settings.py exist. That leads to a situation when I can't run my custom command because automatic check throws exceptions that there is no access to database (indeed, my custom command should create it).

至少在自定义管理命令中,有没有办法强制跳过Django进行的自动 check ?

Is there any way to force skipping automatic check that Django makes, at least in custom management command?

推荐答案

是的,这是

Yes, and this is fully documented; set the requires_system_checks attribute to False in your Command subclass.

这篇关于Django:运行自定义命令时跳过系统检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆