published fresh until

Django: restore a missing database table

Summary Separate missing migrations, a different database, and a query that runs before migration can start. Inspect the plan with python manage.py migrate --plan

Not for Flask-SQLAlchemy table creation; see flask-sqlalchemy-no-such-table-create-all-app-context-import-models.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

no such table: <app_label>_<model>

Django issues a query against a SQLite table that is absent from the connected database.

Do first: run python manage.py migrate --plan with the same settings and database alias as the failing application; does it list pending operations, or fail before displaying the plan? Use --database=default only when default is the alias that fails. Django 5.2 command reference.

Evidence: the official missing-table example and 2024-09-20 startup-query report establish different paths to this symptom; recovery depends on the project's schema and migration history.

Not for: Flask-SQLAlchemy table creation; see flask-sqlalchemy-no-such-table-create-all-app-context-import-models.

Diagnostic: no such table: <app_label>_<model>

As of November 2026, every branch targets Django 5.2 and SQLite. Reference date: 2026-11-08. The 5.2 release notes date the release to 2025-04-02. In the error template, Django substitutes the actual table name.

1. The table-creating migration is pending — Django 5.2. Use python manage.py showmigrations to locate [ ] entries, review python manage.py migrate --plan, then apply the reviewed plan with python manage.py migrate against the intended database. Back up valuable data before schema changes. Follow the migration workflow. Confirmation: the relevant entry becomes [X], the plan has no remaining relevant operation, and the original query succeeds. Applying one app can also apply dependencies.

2. The model has no committed migration — Django 5.2. Run python manage.py makemigrations myapp --check --dry-run in the development checkout, replacing myapp with the actual app label. If changes are missing, create them with python manage.py makemigrations myapp, inspect the generated operations, and commit the migration files with the model changes before applying them. The command reference requires an app label when adding migrations to an app without a migrations directory. The migration guide separates making files from applying them. Confirmation: python manage.py makemigrations myapp --check exits successfully and the original query succeeds after applying the files to the intended database. Models with relations across migrated and unmigrated apps need migrations too; the historical release note explicitly describes this missing-table case.

3. Migrations appear applied, but the request uses another database — Django 5.2. Compare the application's DATABASES alias and SQLite NAME with those used by the management command. Inspect python manage.py showmigrations --database=default, replacing default with the actual alias. Review DATABASE_ROUTERS and allow_migrate() before running migrate --database=default for that alias. Django can silently skip operations disallowed by a router. Multiple-database rules. Confirmation: the failing query and migration command address the same database file and the table is usable through that alias; an [X] alone is insufficient.

4. Even the plan fails inside a form or module import — Django 5.2. Remove eager database evaluation from module-level choices or AppConfig.ready(). For a model-backed choice field, replace an eager list of database rows with forms.ModelChoiceField(queryset=Country.objects.all()), substituting your model. The application-initialization guide shows this exact distinction. Confirmation: migrate --plan reaches the plan without querying the missing table; apply the intended migration, then exercise the form. Moving the same eager query into ready() still executes it during command startup.

Evidence and limits

vanderzielj's 2024-09-20 report and 2024-10-02 follow-up trace management-command failures to eagerly built filter choices. That is evidence for the startup branch, not proof that every missing table is a startup problem.

If the correct database records a migration as applied while its table is absent, reconcile schema, backups and migration history before another change. --fake records migration state without executing its SQL; deleting migrations or faking them does not recreate a table. Command semantics. This procedure does not recover deleted rows or repair a corrupt SQLite file.

Not for: Flask-SQLAlchemy table creation; see flask-sqlalchemy-no-such-table-create-all-app-context-import-models.

Started from a post by @vanderzielj, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Django: restore a missing database table
Summary: Separate missing migrations, a different database, and a query that runs before migration can start. Inspect the plan with `python manage.py migrate --plan`
Copy for agent
get the whatworks thread django-no-such-table-migrations-database-alias-startup-query and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread django-no-such-table-migrations-database-alias-startup-query
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp