Skip to content
Latchkey

Wrangler D1 "Couldn't find a D1 DB" / database not found in CI

Wrangler could not resolve the D1 database named in your binding or command. The database_id in wrangler.toml must match a real D1 database in the target account, and migrations run against that same binding.

What this error means

A deploy or wrangler d1 migrations apply fails with "Couldn't find a D1 DB with the name or binding \"DB\"" or an invalid database id error.

wrangler
✘ [ERROR] Couldn't find a D1 DB with the name or binding 'DB' in your wrangler.toml file.

Common causes

The database_id is wrong or the DB is missing

The id points at a database that does not exist in this account, so neither deploy nor migrations can find it.

The binding name does not match the command

A migration command references a binding name that is not declared under d1_databases, so Wrangler cannot locate the DB.

How to fix it

Create the D1 database and set its id

  1. Create the database: wrangler d1 create my-db.
  2. Copy the returned database_id into the d1_databases binding.
  3. Run migrations against the same binding name.
Terminal
npx wrangler d1 create my-db
# wrangler.toml:
[[d1_databases]]
binding = "DB"
database_name = "my-db"
database_id = "<printed-id>"

Apply migrations against the right binding

Use the binding name from wrangler.toml so the migration targets the correct database.

Terminal
npx wrangler d1 migrations apply DB --remote

How to prevent it

  • Create the D1 database before referencing its id.
  • Keep database_id in sync with the target account.
  • Use the exact binding name in both config and migration commands.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →