Search code examples
djangodjango-manage.py

Django management command: [Errno 61] Connection refused


I have written a Django custom management command—call it command.py. When I run it using manage.py command, I get the following error:

error: [Errno 61] Connection refused

The command doesn't import anything other than the standard BaseCommand and CommandError, as well as my project-specific models. It doesn't make (or shouldn't be making) any SMTP connections, but just in case, I added the following line to settings.py. I get the same error.

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

Details: this is essentially what the command file contains.

from django.core.management.base import BaseCommand, CommandError
from my_app.models import MyModel

class Command(BaseCommand):
    def handle(self, *args, **kwargs):
        for piece in MyModel.objects.all():
            piece.field = 'value'
            piece.save()

Solution

  • Two possibilities:

    1. What does piece.save() do? Is your model trying to send an email on save?
    2. What's your logging setup? Is there an error in your code which your app is trying to email you about?