From 1f4f491023cab4699089623b777bf71bc78a53a8 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 11 Mar 2020 16:07:39 +0900 Subject: [PATCH] Fix duplicate key error, resolve #589 --- app/server/management/commands/create_roles.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/server/management/commands/create_roles.py b/app/server/management/commands/create_roles.py index 6f01f81a..daa0754d 100644 --- a/app/server/management/commands/create_roles.py +++ b/app/server/management/commands/create_roles.py @@ -13,11 +13,13 @@ class Command(BaseCommand): except KeyError as key_error: self.stderr.write(self.style.ERROR(f'Missing Key: "{key_error}"')) for role_name in role_names: + if Role.objects.filter(name=role_name).exists(): + continue role = Role() role.name = role_name try: role.save() except DatabaseError as db_error: - self.stderr.write(self.style.ERROR(f'Datbase Error: "{db_error}"')) + self.stderr.write(self.style.ERROR(f'Database Error: "{db_error}"')) else: self.stdout.write(self.style.SUCCESS(f'Role created successfully "{role_name}"'))