Ticket #25304: try-except-createsuperuser.diff

File try-except-createsuperuser.diff, 1.3 KB (added by Maxime Lorant, 9 years ago)
  • django/contrib/auth/management/commands/createsuperuser.py

    diff --git a/django/contrib/auth/management/commands/createsuperuser.py b/django/contrib/auth/management/commands/createsuperuser.py
    index 558ee64..ae2f213 100644
    a b from django.contrib.auth.password_validation import validate_password  
    1212from django.core import exceptions
    1313from django.core.management.base import BaseCommand, CommandError
    1414from django.db import DEFAULT_DB_ALIAS
     15from django.db.utils import OperationalError
    1516from django.utils.encoding import force_str
    1617from django.utils.six.moves import input
    1718from django.utils.text import capfirst
    class Command(BaseCommand):  
    8283            # Prompt for username/password, and any other required fields.
    8384            # Enclose this whole thing in a try/except to catch
    8485            # KeyboardInterrupt and exit gracefully.
    85             default_username = get_default_username()
     86            try:
     87                default_username = get_default_username()
     88            except OperationalError:
     89                raise CommandError("You must execute `manage.py migrate` once before creating a super user")
    8690            try:
    8791
    8892                if hasattr(self.stdin, 'isatty') and not self.stdin.isatty():
Back to Top