Browse Source

Merge pull request #607 from doccano/hotfix/fix-duplicate-key-error

Fix duplicate key error, resolve #589
pull/611/head
Hiroki Nakayama 4 years ago
committed by GitHub
parent
commit
59b63b127c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions
  1. 4
      app/server/management/commands/create_roles.py

4
app/server/management/commands/create_roles.py

@ -13,11 +13,13 @@ class Command(BaseCommand):
except KeyError as key_error: except KeyError as key_error:
self.stderr.write(self.style.ERROR(f'Missing Key: "{key_error}"')) self.stderr.write(self.style.ERROR(f'Missing Key: "{key_error}"'))
for role_name in role_names: for role_name in role_names:
if Role.objects.filter(name=role_name).exists():
continue
role = Role() role = Role()
role.name = role_name role.name = role_name
try: try:
role.save() role.save()
except DatabaseError as db_error: 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: else:
self.stdout.write(self.style.SUCCESS(f'Role created successfully "{role_name}"')) self.stdout.write(self.style.SUCCESS(f'Role created successfully "{role_name}"'))
Loading…
Cancel
Save