ciur / papermerge

Open Source Document Management System for Digital Archives (Scanned Documents)
https://papermerge.com
Apache License 2.0
2.55k stars 266 forks source link

Migrations don't run cleanly, conflict beteween `auth` and `core` migrations? #578

Closed oliverrahner closed 10 months ago

oliverrahner commented 10 months ago

Description I tried setting up a new installation, but failed. When logging in, I only receive "ERROR" as a message in the frontend, the actual failing request is /api/users/me which returns 500.

I then noticed that the migrations don't run cleanly, but had a hard time at first differentiating the race condition errors (because both worker and web containers tried to apply the migration). But when I only ran web it got clearer. Excerpt from the logs:

papermerge-web-1    | Operations to perform:
papermerge-web-1    |   Apply all migrations: auth, contenttypes, core, sites
papermerge-web-1    | Running migrations:
papermerge-web-1    |   Applying contenttypes.0001_initial... OK
papermerge-web-1    |   Applying contenttypes.0002_remove_content_type_name... OK
papermerge-web-1    |   Applying auth.0001_initial... OK
papermerge-web-1    |   Applying auth.0002_alter_permission_name_max_length... OK
papermerge-web-1    |   Applying auth.0003_alter_user_email_max_length... OK
papermerge-web-1    |   Applying auth.0004_alter_user_username_opts... OK
papermerge-web-1    |   Applying auth.0005_alter_user_last_login_null... OK
papermerge-web-1    |   Applying auth.0006_require_contenttypes_0002... OK
papermerge-web-1    |   Applying auth.0007_alter_validators_add_error_messages... OK
papermerge-web-1    |   Applying auth.0008_alter_user_username_max_length... OK
papermerge-web-1    |   Applying auth.0009_alter_user_last_name_max_length... OK
papermerge-web-1    |   Applying auth.0010_alter_group_name_max_length... OK
papermerge-web-1    |   Applying auth.0011_update_proxy_permissions... OK
papermerge-web-1    |   Applying auth.0012_alter_user_first_name_max_length... OK
papermerge-web-1    | Traceback (most recent call last):
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute
papermerge-web-1    |     return self.cursor.execute(sql)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 75, in execute
papermerge-web-1    |     return self.cursor.execute(query, args)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/MySQLdb/cursors.py", line 179, in execute
papermerge-web-1    |     res = self._query(mogrified_query)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/MySQLdb/cursors.py", line 330, in _query
papermerge-web-1    |     db.query(q)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/MySQLdb/connections.py", line 257, in query
papermerge-web-1    |     _mysql.connection.query(self, query)
papermerge-web-1    | MySQLdb.OperationalError: (1050, "Table 'core_user' already exists")
papermerge-web-1    |
papermerge-web-1    | The above exception was the direct cause of the following exception:
papermerge-web-1    |
papermerge-web-1    | Traceback (most recent call last):
papermerge-web-1    |   File "/core_app/./manage.py", line 22, in <module>
papermerge-web-1    |     main()
papermerge-web-1    |   File "/core_app/./manage.py", line 18, in main
papermerge-web-1    |     execute_from_command_line(sys.argv)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
papermerge-web-1    |     utility.execute()
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
papermerge-web-1    |     self.fetch_command(subcommand).run_from_argv(self.argv)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv
papermerge-web-1    |     self.execute(*args, **cmd_options)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
papermerge-web-1    |     output = self.handle(*args, **options)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper
papermerge-web-1    |     res = handle_func(*args, **kwargs)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 356, in handle
papermerge-web-1    |     post_migrate_state = executor.migrate(
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 135, in migrate
papermerge-web-1    |     state = self._migrate_all_forwards(
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
papermerge-web-1    |     state = self.apply_migration(
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
papermerge-web-1    |     state = migration.apply(state, schema_editor)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/migrations/migration.py", line 132, in apply
papermerge-web-1    |     operation.database_forwards(
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/migrations/operations/models.py", line 96, in database_forwards
papermerge-web-1    |     schema_editor.create_model(model)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 451, in create_model
papermerge-web-1    |     self.execute(sql, params or None)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 201, in execute
papermerge-web-1    |     cursor.execute(sql, params)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
papermerge-web-1    |     return self._execute_with_wrappers(
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
papermerge-web-1    |     return executor(sql, params, many, context)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
papermerge-web-1    |     with self.db.wrap_database_errors:
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
papermerge-web-1    |     raise dj_exc_value.with_traceback(traceback) from exc_value
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute
papermerge-web-1    |     return self.cursor.execute(sql)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 75, in execute
papermerge-web-1    |     return self.cursor.execute(query, args)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/MySQLdb/cursors.py", line 179, in execute
papermerge-web-1    |     res = self._query(mogrified_query)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/MySQLdb/cursors.py", line 330, in _query
papermerge-web-1    |     db.query(q)
papermerge-web-1    |   File "/core_app/.venv/lib/python3.10/site-packages/MySQLdb/connections.py", line 257, in query
papermerge-web-1    |     _mysql.connection.query(self, query)
papermerge-web-1    | django.db.utils.OperationalError: (1050, "Table 'core_user' already exists")
papermerge-web-1    |   Applying core.0001_initial...Installing dependencies from lock file

This was on a clean database.

Info:

oliverrahner commented 10 months ago

I don't know where I went wrong, but after retrying from scratch, the migrations were applied correctly. The original seen problem still persists, though. Opening a new issue for that.