3

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

2

1 Answer 1

9

Do requires_system_checks = False

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

For more info

Sign up to request clarification or add additional context in comments.

2 Comments

I am just wondering, which default commands require a db conneciton and which do not, is this documented?
This does not work for me in Django 2.2.3. I still get OperationalError: could not connect to server: No route to host

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.