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
- Create the database:
wrangler d1 create my-db. - Copy the returned
database_idinto thed1_databasesbinding. - 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 --remoteHow to prevent it
- Create the D1 database before referencing its id.
- Keep
database_idin sync with the target account. - Use the exact binding name in both config and migration commands.
Related guides
Wrangler D1 "migrations failed" to apply in CIFix Wrangler D1 migrations that fail to apply in CI - a SQL error, a missing --remote flag, or an out-of-orde…
Wrangler "binding ... not found" in wrangler.toml in CIFix Wrangler "binding not found" errors in CI - a KV, D1, R2, or service binding in wrangler.toml references…
Wrangler KV "namespace not found" in CIFix Wrangler KV "namespace not found" / "is not valid" in CI - a kv_namespaces binding id in wrangler.toml do…