Skip to content

Default Django Auth migrations don't work #41

@th7nder

Description

@th7nder

Describe the bug

When I run python manage.py migrate on fresh DSQL Cluster with

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

It should migrate properly and it does not.

Current Behavior

$ python manage.py migrate
System check identified some issues:

WARNINGS:
?: (staticfiles.W004) The directory '/Users/th7nder/workspace/bedtime_production/backend/static' in the STATICFILES_DIRS setting does not exist.
2025-07-12 14:03:43,005 - botocore.credentials - INFO - Found credentials in environment variables.
Operations to perform:
  Apply all migrations: accounts, admin, auth, contenttypes, payments, sessions, stories, token_blacklist
Running migrations:
  Applying contenttypes.0001_initial...Traceback (most recent call last):
  File "/Users/th7nder/workspace/bedtime_production/backend/manage.py", line 22, in <module>
    main()
    ~~~~^^
  File "/Users/th7nder/workspace/bedtime_production/backend/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
    ~~~~~~~~~~~~~~~^^
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/core/management/commands/migrate.py", line 353, in handle
    post_migrate_state = executor.migrate(
        targets,
    ...<3 lines>...
        fake_initial=fake_initial,
    )
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
        state, plan, full_plan, fake=fake, fake_initial=fake_initial
    )
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
        state, migration, fake=fake, fake_initial=fake_initial
    )
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 255, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/migrations/migration.py", line 132, in apply
    operation.database_forwards(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self.app_label, schema_editor, old_state, project_state
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/migrations/operations/models.py", line 717, in database_forwards
    alter_together(
    ~~~~~~~~~~~~~~^
        new_model,
        ^^^^^^^^^^
        from_model_state.options.get(self.option_name) or set(),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        to_model_state.options.get(self.option_name) or set(),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/backends/base/schema.py", line 624, in alter_unique_together
    self.execute(s)
    ~~~~~~~~~~~~^^^
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/backends/postgresql/schema.py", line 46, in execute
    sql = self.connection.ops.compose_sql(str(sql), params)
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/backends/postgresql/operations.py", line 202, in compose_sql
    return mogrify(sql, params, self.connection)
  File "/Users/th7nder/workspace/bedtime_production/backend/venv/lib/python3.13/site-packages/django/db/backends/postgresql/psycopg_any.py", line 107, in mogrify
    return cursor.mogrify(sql, params).decode()
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^
psycopg2.ProgrammingError: can't execute an empty query

Reproduction Steps

Setup a django app with default 'admin' django apps which are necessary to build a application.

Possible Solution

I tried to solve some of the issues, but gave up after a point.

  1. Django default migrations are incremental and use ALTER TABLE ADD CONSTRAINT which is not supported. After I created a fresh postgresql docker container, run the migrations on this one and created migrations by hand, still didn't help much, because...
  2. Aurora DSQL doesn't support AUTOINCREMENT/Sequence IDs, so I ended up changing every id to "id" uuid NOT NULL DEFAULT gen_random_uuid(). This doesn't help much as Django is not designed to support uuid in those contrib layers.

There are multiple ways one could try to solve it, like writing own contrib.apps with ready-made authentication and stuff.
Curious what's your opinion on that.

Additional Information/Context

No response

version

0.1.0

Environment details (Version of Python, OS environment)

MacOS 15.5

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions