Skip to content

Revision 1 — the current text. The evidence on this page is this revision’s own — it has not been carried forward from, or to, any other revision.

Fixing DrizzleError from a missing column or table on D1

Covers schema.ts drifting ahead of the generated migrations, and a migration that exists but was applied to only one of D1's local/remote targets. Does not cover Drizzle Studio or Drizzle Kit connection errors (a different failure mode with different messages), and does not cover the equivalent D1_ERROR: no such table thrown outside of Drizzle — see the general D1 migration-not-applied playbook for that.

Unverifiedno reproductions yetWhy this confidence?
Revision 1published by DevYou curation

Symptoms

The diagnostic path

8 steps, exactly as this revision published them.

  1. Step 1 · StartDrizzleError: column/table does not exist

    A query built from a Drizzle schema fails because the underlying D1 database doesn't actually have the column or table the schema.ts model describes.

    What happens next

    • passed step 2, Check whether a migration for this change was ever generated
  2. Step 2 · TestCheck whether a migration for this change was ever generated

    Confirm drizzle-kit generate was run after the schema.ts change that added this column/table — editing schema.ts alone does not touch the database; Drizzle only produces SQL when you explicitly generate a migration from the diff.

    Read-onlysh
    grep -rl "<column_or_table_name>" drizzle/*.sql

    Expected result

    No migration file mentions the column/table — schema.ts and the migrations folder have drifted apart.

    What happens next

    • passed step 3, Generate and apply the missing migration
    • failed step 4, Check whether the migration exists but wasn't applied to this target
    • unknown step 3, Generate and apply the missing migration
  3. Step 3 · FixGenerate and apply the missing migration

    Generate a migration from the current schema.ts, then apply it to the target that's failing.

    Changes statesh

    Changes system or service state. Review before running.

    Creates a new .sql migration reflecting the current schema.ts and applies it to the remote D1 database, adding the missing column/table. Existing rows keep their data; only the schema changes.

    npx drizzle-kit generate
    npx wrangler d1 migrations apply <DATABASE_NAME> --remote

    What happens next

    • passed step 5, Confirm the column exists, then re-run the query
  4. Step 4 · TestCheck whether the migration exists but wasn't applied to this target

    D1 keeps separate local and remote databases, and each needs its own wrangler d1 migrations apply run. A migration generated and applied locally during development is not automatically applied to the remote database used in production, or vice versa.

    Read-onlysh
    npx wrangler d1 migrations list <DATABASE_NAME> --remote

    Expected result

    The migration that adds the column/table is listed as not yet applied for this target.

    What happens next

    • passed step 6, Apply the pending migration to the failing target
    • failed step 7, Migration exists and is applied — escalate
    • unknown step 7, Migration exists and is applied — escalate
  5. Step 5 · Verify the fixConfirm the column exists, then re-run the query

    Check the table schema directly against the target that was failing, then repeat the Drizzle query that threw.

    Read-onlysh
    npx wrangler d1 execute <DATABASE_NAME> --remote --command "PRAGMA table_info(orders);"

    Expected result

    The column/table is listed, and the Drizzle query that previously threw now returns normally.

    What happens next

    • passed step 8, Resolved
    • failed step 7, Migration exists and is applied — escalate
    • unknown step 7, Migration exists and is applied — escalate
  6. Step 6 · FixApply the pending migration to the failing target

    Run migrations apply against whichever target (local or remote) is missing it — run both if both need it, since they're independent.

    Changes statesh

    Changes system or service state. Review before running.

    Applies any migrations D1 hasn't recorded yet, separately for each target given. Already-applied migrations and existing data are untouched.

    npx wrangler d1 migrations apply <DATABASE_NAME> --local
    npx wrangler d1 migrations apply <DATABASE_NAME> --remote

    What happens next

    • passed step 5, Confirm the column exists, then re-run the query
  7. Step 7 · EndMigration exists and is applied — escalate

    Check that migrations_pattern/migrations_dir in your Wrangler configuration actually match where drizzle-kit writes its output. A mismatch means wrangler d1 migrations apply silently finds nothing new to apply, even though drizzle-kit did generate a file — this is common when Drizzle's default output layout doesn't match wrangler's default migrations/*.sql glob.

  8. Step 8 · EndResolved

    The database schema now matches schema.ts on the target that was failing.

Sources

Why this confidence?

What would strengthen it: 6 more independent reproductions. Reproductions from 3 more distinct environments.

This counts only what was recorded against revision 1 itself. Nothing reported against another revision is included here — see the revision history for why.