pythondjangodjango-management-command

Django management command without working db connection


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


Solution

  • Do requires_system_checks = False

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

    For more info