Django management command without working db connection

只愿长相守 提交于 2019-12-20 03:54:28

问题


I have a number of projects that use the following configuration model:

settings.py includes default configuration and config specifications, mainly used for development purposes. The default settings (including db settings) can be overridden by external configuration files, usually defined by admins for the various environments they manage. In order to ease the admins, I have written a management command and packaged separately, which adds the option to create example configuration files based on the default configuration in settings.py

Trying to run the command without the possibility for successful db connection, however, raises django.db.utils.OperationalError.

How can I make the command work without db connection, as it does not need one and normally when the command is needed, most probably the db connection is not configured properly.

settings.DATABASES != {} as there are the default db settings.

Django 1.10.6, Python 3.5.3


回答1:


Do requires_system_checks = False

class Command(BaseCommand):
    requires_system_checks = False
    ...
    def add_arguments(self, parser):
        #rest of code

For more info



来源:https://stackoverflow.com/questions/47179297/django-management-command-without-working-db-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!