diff --git a/openslides/users/signals.py b/openslides/users/signals.py index c53f0ee0e..8c6b7619d 100644 --- a/openslides/users/signals.py +++ b/openslides/users/signals.py @@ -1,5 +1,6 @@ from django.apps import apps from django.contrib.auth.models import Permission +from django.db import connection from django.db.models import Q from ..utils.auth import GROUP_ADMIN_PK, GROUP_DEFAULT_PK @@ -185,3 +186,12 @@ def create_builtin_groups_and_admin(**kwargs): # After each group was created, the permissions (many to many fields) where # added to the group. But we do not have to update the cache by calling # inform_changed_data() because the cache is updated on server start. + + # For postgres, the id sequence (the current auto increment value for the id field) + # needs to be refreshed after inserting the groups per id, because postgres does not + # increment the sequence then. + if connection.vendor == "postgresql": + with connection.cursor() as cursor: + cursor.execute("SELECT max(id) + 1 as max FROM auth_group;") + max_id = cursor.fetchone()[0] + cursor.execute(f"ALTER SEQUENCE auth_group_id_seq RESTART WITH {max_id};")