the document exporter does not export the user groups as well. These are missing in the manifest.json. There is no entry of the model auth.group
.
For the exported users, however, the group ID numbers are exported as well.
{
"model": "auth.user",
"pk": 3,
"fields": {
"password": "...",
"last_login": "2022-02-23T22:32:02Z",
"is_superuser": false,
"username": "TestUser",
"first_name": "TestUser",
"last_name": "TestUser",
"email": "[email protected]",
"is_staff": true,
"is_active": true,
"date_joined": "2022-02-23T22:28:51Z",
"groups": [
1
],
"user_permissions": []
}
},
Since the stored user groups are unknown to the document_importer, an error occurs during the import.
sudo docker-compose exec -T webserver document_importer ../export
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
psycopg2.errors.ForeignKeyViolation: insert or update on table "auth_user_groups" violates foreign key constraint "auth_user_groups_group_id_97559544_fk_auth_group_id"
DETAIL: Key (group_id)=(1) is not present in table "auth_group".
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/paperless/src/manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/usr/src/paperless/src/documents/management/commands/document_importer.py", line 78, in handle
call_command("loaddata", manifest_path)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 181, in call_command
return command.execute(*args, **defaults)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
self.loaddata(fixture_labels)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/loaddata.py", line 131, in loaddata
connection.check_constraints(table_names=table_names)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 285, in check_constraints
cursor.execute('SET CONSTRAINTS ALL IMMEDIATE')
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
django.db.utils.IntegrityError: Problem installing fixtures: insert or update on table "auth_user_groups" violates foreign key constraint "auth_user_groups_group_id_97559544_fk_auth_group_id"
DETAIL: Key (group_id)=(1) is not present in table "auth_group".
ERROR: 1
After deleting the user group, the import is completed successfully. However, this cannot be the solution.
The backup function via the document_exporter, as well as the import via the document_importer must be working, so that a regular complete backup of the dataset can be performed, which can also be successfully imported later.
The backup of the database files is a simple and good way, but is not 100% safe. Especially if the database version and therefore the database files change.