Wrangler commands (5)·续
</details>
d1 time-travel restore
Restore a database back to a specific point-in-time
This command acts on remote D1 Databases.
For more information about Time Travel, see https://developers.cloudflare.com/d1/reference/time-travel/
npmyarnpnpm
npx wrangler d1 time-travel restore <DATABASE>
yarn wrangler d1 time-travel restore <DATABASE>
pnpm wrangler d1 time-travel restore <DATABASE>
<DATABASE>stringrequired
The name or binding of the DB
- --bookmark string Bookmark to use for time travel
- --timestamp string Accepts a Unix (seconds from epoch) or RFC3339 timestamp (e.g. 2023-07-13T08:46:42.228Z) to retrieve a bookmark for (within the last 30 days)
- --json boolean default: false
Return output as JSON
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
d1 migrations create
Create a new migration
This will generate a new versioned file inside the 'migrations' folder. Name your migration file as a description of your change. This will make it easier for you to find your migration in the 'migrations' folder. An example filename looks like:
0000_create_user_table.sql
The filename will include a version number and the migration name you specify.
npmyarnpnpm
npx wrangler d1 migrations create <DATABASE> <MESSAGE>
yarn wrangler d1 migrations create <DATABASE> <MESSAGE>
pnpm wrangler d1 migrations create <DATABASE> <MESSAGE>
<DATABASE>stringrequired
The name or binding of the DB
- <MESSAGE> string required
The Migration message
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
d1 migrations list
View a list of unapplied migration files
npmyarnpnpm
npx wrangler d1 migrations list <DATABASE>
yarn wrangler d1 migrations list <DATABASE>
pnpm wrangler d1 migrations list <DATABASE>
<DATABASE>stringrequired
The name or binding of the DB
- --local boolean Check migrations against a local DB for use with wrangler dev
- --remote boolean Check migrations against a remote DB for use with wrangler dev --remote
- --preview boolean default: false
Check migrations against a preview D1 DB
- --persist-to string Specify directory to use for local persistence (you must use --local with this flag)
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
d1 migrations apply
Apply any unapplied D1 migrations
This command will prompt you to confirm the migrations you are about to apply. Confirm that you would like to proceed. After applying, a backup will be captured.
The progress of each migration will be printed in the console.
When running the apply command in a CI/CD environment or another non-interactive command line, the confirmation step will be skipped, but the backup will still be captured.
If applying a migration results in an error, this migration will be rolled back, and the previous successful migration will remain applied.
npmyarnpnpm
npx wrangler d1 migrations apply <DATABASE>
yarn wrangler d1 migrations apply <DATABASE>
pnpm wrangler d1 migrations apply <DATABASE>
<DATABASE>stringrequired
The name or binding of the DB
- --local boolean Execute commands/files against a local DB for use with wrangler dev
- --remote boolean Execute commands/files against a remote DB for use with wrangler dev --remote
- --preview boolean default: false
Execute commands/files against a preview D1 DB
- --persist-to string Specify directory to use for local persistence (you must use --local with this flag)
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
d1 insights
Experimental
Get information about the queries run on a D1 database
This command acts on remote D1 Databases.
npmyarnpnpm
npx wrangler d1 insights <NAME>
yarn wrangler d1 insights <NAME>
pnpm wrangler d1 insights <NAME>
<NAME>stringrequired
The name of the DB
- --time-period string default: 1d
Fetch data from now to the provided time period
- --sort-type string default: sum
Choose the operation you want to sort insights by
- --sort-by string default: time
Choose the field you want to sort insights by
- --sort-direction string default: DESC
Choose a sort direction
- --limit number default: 5
fetch insights about the first X queries
- --json boolean default: false
return output as JSON
<details>
<summary>
Global flags
</summary>
- <code>--v</code><code>boolean</code> alias: --version
Show version number - <code>--cwd</code><code>string</code>Run as if Wrangler was started in the specified directory instead of the current working directory - <code>--config</code><code>string</code> alias: --c
Path to Wrangler configuration file - <code>--env</code><code>string</code> alias: --e
Environment to use for operations, and for selecting .env and .dev.vars files - <code>--env-file</code><code>string</code>Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files - <code>--install-skills</code><code>boolean</code> default: false
Install Cloudflare skills for detected AI coding agents before running the command - <code>--profile</code><code>string</code>Use a specific auth profile
</details>
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/d1/wrangler-commands/#page","headline":"Wrangler commands","description":"Use Wrangler CLI commands to create, manage, and query D1 databases.","url":"https://developers.cloudflare.com/d1/wrangler-commands/","inLanguage":"en","image":"https://developers.cloudflare.com/d1/wrangler-commands/og.png?v=b088110ac526a410","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
title: Create D1 Database
Copy Markdown
Open in ClaudeOpen in ChatGPTOpen in Cursor
Copy MarkdownView as Markdown
Docs