From 7e30a1e756d9b4803268558249eb11dae1e82136 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 17 Jul 2019 13:09:24 -0400 Subject: [PATCH] Create admin if it doesn't exist --- app/server/management/commands/create_admin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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')