[{"data":1,"prerenderedAt":48},["ShallowReactive",2],{"\u002Fcloudflare-config\u002Fd1":3},{"title":4,"description":5,"path":6,"date":7,"updated":8,"verified":7,"category":9,"keywords":10,"officialSources":16,"related":26,"readingTime":30,"html":31,"toc":32},"D1 bindings in cloudflare.config.ts","Add a D1 binding under worker.env, distinguish its application name from its database identity, and apply migrations to the correct target.","\u002Fcloudflare-config\u002Fd1","2026-09-29","2026-09-30","Configuration",[11,12,13,14,15],"cloudflare.config.ts d1","cloudflare d1 config example","cf d1 migrations","d1 binding cloudflare.config.ts","cf d1 migrations apply",[17,20,23],{"label":18,"url":19},"Cloudflare configuration types and helpers","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fworkers-sdk\u002Ftree\u002Fmain\u002Fpackages\u002Fconfig\u002Fsrc",{"label":21,"url":22},"cf CLI source and README","https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fcf\u002Ftree\u002Fmain\u002Fpackages\u002Fcli",{"label":24,"url":25},"D1 local development","https:\u002F\u002Fdevelopers.cloudflare.com\u002Fd1\u002Fbest-practices\u002Flocal-development\u002F",[27,28,29],"\u002Fcloudflare-config","\u002Fcloudflare-config\u002Fkv","\u002Fcf-deploy",2,"\u003Ch2 id=\"quick-configuration\">Quick configuration\u003C\u002Fh2>\n\u003Cdiv class=\"code-block\">\u003Cdiv class=\"code-toolbar\">\u003Cspan>cloudflare.config.ts\u003C\u002Fspan>\u003Cbutton type=\"button\" data-copy-code aria-label=\"Copy code\">Copy\u003C\u002Fbutton>\u003C\u002Fdiv>\u003Cpre>\u003Ccode class=\"hljs language-ts\">\u003Cspan class=\"hljs-keyword\">import\u003C\u002Fspan> { bindings, defineConfig } \u003Cspan class=\"hljs-keyword\">from\u003C\u002Fspan> \u003Cspan class=\"hljs-string\">&quot;cf\u002Fconfig&quot;\u003C\u002Fspan>;\n\n\u003Cspan class=\"hljs-keyword\">export\u003C\u002Fspan> \u003Cspan class=\"hljs-keyword\">default\u003C\u002Fspan> \u003Cspan class=\"hljs-title function_\">defineConfig\u003C\u002Fspan>({\n  \u003Cspan class=\"hljs-attr\">worker\u003C\u002Fspan>: {\n    \u003Cspan class=\"hljs-attr\">name\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;notes-worker&quot;\u003C\u002Fspan>,\n    \u003Cspan class=\"hljs-attr\">compatibilityDate\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;2026-09-29&quot;\u003C\u002Fspan>,\n    \u003Cspan class=\"hljs-attr\">entrypoint\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;.\u002Fsrc\u002Findex.ts&quot;\u003C\u002Fspan>,\n    \u003Cspan class=\"hljs-attr\">env\u003C\u002Fspan>: {\n      \u003Cspan class=\"hljs-attr\">DB\u003C\u002Fspan>: bindings.\u003Cspan class=\"hljs-title function_\">d1\u003C\u002Fspan>({ \u003Cspan class=\"hljs-attr\">name\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;notes-db&quot;\u003C\u002Fspan> }),\n    },\n  },\n});\n\u003C\u002Fcode>\u003C\u002Fpre>\u003C\u002Fdiv>\u003Cp>The binding key is \u003Ccode>DB\u003C\u002Fcode>, so Worker code accesses \u003Ccode>env.DB\u003C\u002Fcode>. \u003Ccode>notes-db\u003C\u002Fcode> identifies the database by name. The current helper also accepts \u003Ccode>id\u003C\u002Fcode>; use the actual database UUID if you want an explicit identifier.\u003C\u002Fp>\n\u003Ch2 id=\"reference-an-existing-database\">Reference an existing database\u003C\u002Fh2>\n\u003Cdiv class=\"code-block\">\u003Cdiv class=\"code-toolbar\">\u003Cspan>cloudflare.config.ts\u003C\u002Fspan>\u003Cbutton type=\"button\" data-copy-code aria-label=\"Copy code\">Copy\u003C\u002Fbutton>\u003C\u002Fdiv>\u003Cpre>\u003Ccode class=\"hljs language-ts\">\u003Cspan class=\"hljs-keyword\">import\u003C\u002Fspan> { bindings, defineConfig } \u003Cspan class=\"hljs-keyword\">from\u003C\u002Fspan> \u003Cspan class=\"hljs-string\">&quot;cf\u002Fconfig&quot;\u003C\u002Fspan>;\n\n\u003Cspan class=\"hljs-keyword\">export\u003C\u002Fspan> \u003Cspan class=\"hljs-keyword\">default\u003C\u002Fspan> \u003Cspan class=\"hljs-title function_\">defineConfig\u003C\u002Fspan>({\n  \u003Cspan class=\"hljs-attr\">worker\u003C\u002Fspan>: {\n    \u003Cspan class=\"hljs-attr\">name\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;notes-worker&quot;\u003C\u002Fspan>,\n    \u003Cspan class=\"hljs-attr\">compatibilityDate\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;2026-09-29&quot;\u003C\u002Fspan>,\n    \u003Cspan class=\"hljs-attr\">entrypoint\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;.\u002Fsrc\u002Findex.ts&quot;\u003C\u002Fspan>,\n    \u003Cspan class=\"hljs-attr\">env\u003C\u002Fspan>: {\n      \u003Cspan class=\"hljs-attr\">DB\u003C\u002Fspan>: bindings.\u003Cspan class=\"hljs-title function_\">d1\u003C\u002Fspan>({ \u003Cspan class=\"hljs-attr\">id\u003C\u002Fspan>: \u003Cspan class=\"hljs-string\">&quot;REPLACE_WITH_DATABASE_UUID&quot;\u003C\u002Fspan> }),\n    },\n  },\n});\n\u003C\u002Fcode>\u003C\u002Fpre>\u003C\u002Fdiv>\u003Cp>Replace the placeholder before deployment. A binding declaration does not contain your table schema and does not apply SQL migrations.\u003C\u002Fp>\n\u003Ch2 id=\"create-and-migrate-deliberately\">Create and migrate deliberately\u003C\u002Fh2>\n\u003Cdiv class=\"code-block\">\u003Cdiv class=\"code-toolbar\">\u003Cspan>Terminal\u003C\u002Fspan>\u003Cbutton type=\"button\" data-copy-code aria-label=\"Copy code\">Copy\u003C\u002Fbutton>\u003C\u002Fdiv>\u003Cpre>\u003Ccode class=\"hljs language-bash\">\u003Cspan class=\"hljs-comment\"># Creates a remote database after authentication\u003C\u002Fspan>\ncf d1 create --name notes-db\n\n\u003Cspan class=\"hljs-comment\"># Inspect flags and targets first\u003C\u002Fspan>\ncf d1 migrations apply --\u003Cspan class=\"hljs-built_in\">help\u003C\u002Fspan>\n\n\u003Cspan class=\"hljs-comment\"># Replace the ID with the returned database UUID\u003C\u002Fspan>\ncf d1 migrations apply DATABASE_UUID --\u003Cspan class=\"hljs-built_in\">dir\u003C\u002Fspan> migrations --\u003Cspan class=\"hljs-built_in\">local\u003C\u002Fspan>\n\u003C\u002Fcode>\u003C\u002Fpre>\u003C\u002Fdiv>\u003Cp>For this beta, the migration command requires a database ID. The name or \u003Ccode>DB\u003C\u002Fcode> binding is not interchangeable with that positional argument. Removing \u003Ccode>--local\u003C\u002Fcode> targets the remote database; do so only after reviewing the SQL and the selected account.\u003C\u002Fp>\n\u003Cp>Local development uses simulated data separate from the remote database. Verify the state directory used by your development and migration commands. Passing a different persistence directory can make a populated local database appear empty.\u003C\u002Fp>\n\u003Ch2 id=\"from-wrangler-configuration\">From Wrangler configuration\u003C\u002Fh2>\n\u003Cp>Wrangler separates \u003Ccode>binding\u003C\u002Fcode>, \u003Ccode>database_name\u003C\u002Fcode> and \u003Ccode>database_id\u003C\u002Fcode> inside \u003Ccode>d1_databases\u003C\u002Fcode>. In the new format, the object key supplies the binding name and \u003Ccode>bindings.d1\u003C\u002Fcode> carries the resource reference. Let \u003Ca href=\"\u002Fwrangler-to-cf\">cf migrate\u003C\u002Fa> perform the source conversion, then inspect these identities.\u003C\u002Fp>\n\u003Ch2 id=\"common-mistakes\">Common mistakes\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>Using a database name in the migration command that requires an ID.\u003C\u002Fli>\n\u003Cli>Running remote migrations when you intended to seed local state.\u003C\u002Fli>\n\u003Cli>Changing the binding key without updating \u003Ccode>env.DB\u003C\u002Fcode> references in application code.\u003C\u002Fli>\n\u003Cli>Treating a successful Worker deployment as proof that required tables exist.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Return to the \u003Ca href=\"\u002Fcloudflare-config\">configuration guide\u003C\u002Fa> to combine D1 with other bindings, or use the \u003Ca href=\"\u002Fcloudflare-config-builder\">builder\u003C\u002Fa> for a typed starting point.\u003C\u002Fp>\n",[33,36,39,42,45],{"id":34,"text":35},"quick-configuration","Quick configuration",{"id":37,"text":38},"reference-an-existing-database","Reference an existing database",{"id":40,"text":41},"create-and-migrate-deliberately","Create and migrate deliberately",{"id":43,"text":44},"from-wrangler-configuration","From Wrangler configuration",{"id":46,"text":47},"common-mistakes","Common mistakes",1790729614466]