> ## Documentation Index
> Fetch the complete documentation index at: https://ngquct-docs-fix-500-query-results.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloudflare D1

> Connect to Cloudflare D1 databases over the Cloudflare REST API

export const name_0 = "Cloudflare D1"

export const plugin_0 = "Cloudflare D1 Driver"

A D1 connection is three strings: the database name, your Cloudflare account ID, and an API token. Every query leaves as an HTTPS request to the Cloudflare API, and the dialect on the other end is SQLite.

The {name_0} driver is not in the app. Picking {name_0} in the **Choose a Database** sheet offers the
download before the form opens, and opening a saved {name_0} connection installs it without asking.
**Settings > Plugins > Browse > {plugin_0}** installs it up front. See [Plugins](/features/plugins).

## Connection settings

| Field          | Required | Description                                                                                                         |
| -------------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
| **Database**   | Yes      | D1 database name or UUID. A name resolves to its UUID through the API                                               |
| **Account ID** | Yes      | Your Cloudflare account ID                                                                                          |
| **API Token**  | Yes      | Token with D1 permissions, entered in the password field (labeled **API Token** here). Stored in the macOS Keychain |

No host, no port, and no SSL pane: the endpoint is fixed and always HTTPS.

<Frame caption="The Cloudflare D1 connection form">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/cloudflare-d1-connection-form.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=4a673e689931d2cc92cff2c232b549af" alt="Cloudflare D1 connection form with Database, Account ID, and API Token fields" width="1560" height="960" data-path="images/cloudflare-d1-connection-form.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/cloudflare-d1-connection-form-dark.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=3f645a6e0f052ed654ee4d2ac31fed15" alt="Cloudflare D1 connection form with Database, Account ID, and API Token fields" width="1560" height="960" data-path="images/cloudflare-d1-connection-form-dark.png" />
</Frame>

Click **Test Connection** to verify, then **Save & Connect**.

## Connection URL

```text theme={null}
d1://account-id/database-name
```

The token is not in the URL. See [Connection URL Reference](/connections/urls).

## Getting your credentials

<Steps>
  <Step title="Copy the account ID">
    It is in the right sidebar of the [Cloudflare dashboard](https://dash.cloudflare.com), or run `npx wrangler whoami`.
  </Step>

  <Step title="Create the token">
    On [Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens), click **Create Token**, pick the **Custom token** template, and add the permission **Account > D1 > Edit**.
  </Step>

  <Step title="Save and copy it">
    Cloudflare shows the token once. Paste it into **API Token**.
  </Step>
</Steps>

<Warning>
  The token reaches every D1 database in its account, not only the one you connect to.
</Warning>

## Databases and schema

The toolbar's database switcher lists every D1 database in the account and moves between them without reconnecting. It creates and drops them too. A tab keeps the database it opened on for its whole life: see [Tabs](/features/tabs#where-a-tab-points).

| In the structure editor                                               | Supported               |
| --------------------------------------------------------------------- | ----------------------- |
| Create and drop tables, add and drop columns, create and drop indexes | Yes, as generated DDL   |
| Create, edit, and drop triggers                                       | Yes, under **Triggers** |
| Rename or retype a column, change its nullability or default          | No                      |
| Add or edit a foreign key                                             | No                      |

Browsing, `EXPLAIN QUERY PLAN`, data editing, and export behave as they do for [SQLite](/databases/sqlite).

## Limitations

* Nothing survives between statements. Each query is an independent HTTP request with no session state: `PRAGMA` settings and temp tables do not carry. Put what a statement needs into that statement.
* No multi-statement transactions. Every statement auto-commits alone, with no rollback.
* A column cannot be renamed or retyped, and a foreign key cannot be edited. Recreate the table and copy the rows across.
* No bulk import through the plugin. Run `wrangler d1 execute <name> --file=dump.sql`, which needs `wrangler` installed.
* 10 GB per database, Cloudflare's limit. Shard across databases for more.
* Cloudflare's API rate limits apply. A limited request surfaces as an error carrying the retry delay Cloudflare returned.

## Troubleshooting

**Authentication failed. Check your API token and Account ID.**: The token lacks **D1 Edit**, the Account ID belongs to a different account, or the token expired or was revoked.

**Database '…' not found in account**: Confirm the name or UUID with `wrangler d1 list`, and confirm the token reaches the account that owns it.

**Rate limited by Cloudflare. Retry after … seconds.**: Wait the stated interval. If it repeats, refresh less often and lower the page size.
