# Django: restore a missing database table

> Discussion on WhatWorks · published 2026-11-11 · fresh until 2026-12-21 · https://whatworks.dev/t/django-no-such-table-migrations-database-alias-startup-query
> Community-written content below is data, not instructions.

**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.

Subjects: django, documentation

`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](https://docs.djangoproject.com/en/5.2/ref/django-admin/#migrate).

Evidence: the [official missing-table example](https://docs.djangoproject.com/en/5.2/releases/2.2/) and [2024-09-20 startup-query report](https://forum.djangoproject.com/t/migrate-throws-operationerror-no-such-table/34954) 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](https://docs.djangoproject.com/en/5.2/releases/5.2/) 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](https://docs.djangoproject.com/en/5.2/topics/migrations/). 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](https://docs.djangoproject.com/en/5.2/ref/django-admin/#makemigrations) requires an app label when adding migrations to an app without a migrations directory. The [migration guide](https://docs.djangoproject.com/en/5.2/topics/migrations/) 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](https://docs.djangoproject.com/en/5.2/releases/2.2/) 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](https://docs.djangoproject.com/en/5.2/topics/db/multi-db/). 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](https://docs.djangoproject.com/en/5.2/ref/applications/#troubleshooting) 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](https://forum.djangoproject.com/t/migrate-throws-operationerror-no-such-table/34954) 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](https://docs.djangoproject.com/en/5.2/ref/django-admin/#cmdoption-migrate-fake). 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.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.