Skip to content

Commit 7e30a1e

Browse files
committed
Create admin if it doesn't exist
1 parent ddef7de commit 7e30a1e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/server/management/commands/create_admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.contrib.auth.management.commands import createsuperuser
22
from django.core.management import CommandError
3+
from django.db import IntegrityError
34

45

56
class Command(createsuperuser.Command):
@@ -17,7 +18,10 @@ def handle(self, *args, **options):
1718
if password and not username:
1819
raise CommandError('--username is required if specifying --password')
1920

20-
super().handle(*args, **options)
21+
try:
22+
super().handle(*args, **options)
23+
except IntegrityError:
24+
self.stderr.write(f'User {username} already exists.')
2125

2226
if password:
2327
database = options.get('database')

0 commit comments

Comments
 (0)