diff --git a/app/server/management/commands/create_admin.py b/app/server/management/commands/create_admin.py index fb633dfe..e9e145c6 100644 --- a/app/server/management/commands/create_admin.py +++ b/app/server/management/commands/create_admin.py @@ -1,5 +1,6 @@ from django.contrib.auth.management.commands import createsuperuser from django.core.management import CommandError +from django.db import IntegrityError class Command(createsuperuser.Command): @@ -17,7 +18,10 @@ class Command(createsuperuser.Command): if password and not username: raise CommandError('--username is required if specifying --password') - super().handle(*args, **options) + try: + super().handle(*args, **options) + except IntegrityError: + self.stderr.write(f'User {username} already exists.') if password: database = options.get('database')