---
title: Create D1 Database
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[D1](https://developers.cloudflare.com/api/go/resources/d1)

[Database](https://developers.cloudflare.com/api/go/resources/d1/subresources/database)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Create D1 Database

client.D1.Database.New(ctx, params) (\*[D1](<https://developers.cloudflare.com/api/go/resources/d1#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)>), error)

POST/accounts/{account\_id}/d1/database

Create a new D1 database in your account.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`D1 Write`

##### ParametersExpand Collapse

<details>

<summary>

params DatabaseNewParams

</summary>

AccountID param.Field\[string]

Path param: Account identifier tag.

maxLength32

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

Name param.Field\[string]

Body param: D1 database name.

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20name">Link to this property</a>

<details>

<summary>

Jurisdiction param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction%20%3E%20(schema)">DatabaseNewParamsJurisdiction</a>]Optional

Body param: Specify the location to restrict the D1 database to run and store data. If this option is present, the location hint is ignored.

</summary>

const DatabaseNewParamsJurisdictionEu <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction%20%3E%20(schema)">DatabaseNewParamsJurisdiction</a> = "eu"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction%20%3E%20(schema)%20%3E%20(member)%200">Link to this property</a>

const DatabaseNewParamsJurisdictionFedramp <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction%20%3E%20(schema)">DatabaseNewParamsJurisdiction</a> = "fedramp"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction%20%3E%20(schema)%20%3E%20(member)%201">Link to this property</a>

const DatabaseNewParamsJurisdictionUs <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction%20%3E%20(schema)">DatabaseNewParamsJurisdiction</a> = "us"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction%20%3E%20(schema)%20%3E%20(member)%202">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20jurisdiction">Link to this property</a>

<details>

<summary>

PrimaryLocationHint param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)">DatabaseNewParamsPrimaryLocationHint</a>]Optional

Body param: Specify the region to create the D1 primary, if available. If this option is omitted, the D1 will be created as close as possible to the current user.

</summary>

const DatabaseNewParamsPrimaryLocationHintWnam <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)">DatabaseNewParamsPrimaryLocationHint</a> = "wnam"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)%20%3E%20(member)%200">Link to this property</a>

const DatabaseNewParamsPrimaryLocationHintEnam <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)">DatabaseNewParamsPrimaryLocationHint</a> = "enam"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)%20%3E%20(member)%201">Link to this property</a>

const DatabaseNewParamsPrimaryLocationHintWeur <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)">DatabaseNewParamsPrimaryLocationHint</a> = "weur"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)%20%3E%20(member)%202">Link to this property</a>

const DatabaseNewParamsPrimaryLocationHintEeur <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)">DatabaseNewParamsPrimaryLocationHint</a> = "eeur"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)%20%3E%20(member)%203">Link to this property</a>

const DatabaseNewParamsPrimaryLocationHintApac <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)">DatabaseNewParamsPrimaryLocationHint</a> = "apac"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)%20%3E%20(member)%204">Link to this property</a>

const DatabaseNewParamsPrimaryLocationHintOc <a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)">DatabaseNewParamsPrimaryLocationHint</a> = "oc"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint%20%3E%20(schema)%20%3E%20(member)%205">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20primary_location_hint">Link to this property</a>

<details>

<summary>

ReadReplication param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/d1/subresources/database/methods/create#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20read_replication%20%3E%20(schema)">DatabaseNewParamsReadReplication</a>]Optional

Body param: Configuration for D1 read replication.

</summary>

<details>

<summary>

Mode DatabaseNewParamsReadReplicationMode

The read replication mode for the database. Use ‘auto’ to create replicas and allow D1 automatically place them around the world, or ‘disabled’ to not use any database replicas (it can take a few hours for all replicas to be deleted).

</summary>

One of the following:

const DatabaseNewParamsReadReplicationModeAuto DatabaseNewParamsReadReplicationMode = "auto"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20read_replication%20%3E%20(schema)%20%3E%20(property)%20mode%20%3E%20(member)%200">Link to this property</a>

const DatabaseNewParamsReadReplicationModeDisabled DatabaseNewParamsReadReplicationMode = "disabled"

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20read_replication%20%3E%20(schema)%20%3E%20(property)%20mode%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20read_replication%20%3E%20(schema)%20%3E%20(property)%20mode">Link to this property</a>

</details>

<a href="#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default%20%3E%20(param)%20read_replication">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1.database%20%3E%20(method)%20create%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type D1 struct{…}

The details of the D1 database.

</summary>

CreatedAt TimeOptional

Specifies the timestamp the resource was created as an ISO8601 string.

formatdate-time

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20created_at">Link to this property</a>

FileSize float64Optional

The D1 database’s size, in bytes.

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20file_size">Link to this property</a>

<details>

<summary>

Jurisdiction D1JurisdictionOptional

Specify the location to restrict the D1 database to run and store data. If this option is present, the location hint is ignored.

</summary>

One of the following:

const D1JurisdictionEu D1Jurisdiction = "eu"

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20jurisdiction%20%3E%20(member)%200">Link to this property</a>

const D1JurisdictionFedramp D1Jurisdiction = "fedramp"

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20jurisdiction%20%3E%20(member)%201">Link to this property</a>

const D1JurisdictionUs D1Jurisdiction = "us"

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20jurisdiction%20%3E%20(member)%202">Link to this property</a>

</details>

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20jurisdiction">Link to this property</a>

Name stringOptional

D1 database name.

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20name">Link to this property</a>

DeprecatedNumTables float64Optional

The number of tables in the D1 database. This count is no longer accurate and should not be relied upon.

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20num_tables">Link to this property</a>

<details>

<summary>

ReadReplication D1ReadReplicationOptional

Configuration for D1 read replication.

</summary>

<details>

<summary>

Mode D1ReadReplicationMode

The read replication mode for the database. Mode ‘auto’ denotes that D1 creates replicas and automatically places them around the world. Mode ‘disabled’ denotes that no database replicas are used.

</summary>

One of the following:

const D1ReadReplicationModeAuto D1ReadReplicationMode = "auto"

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20read_replication%20%3E%20(property)%20mode%20%3E%20(member)%200">Link to this property</a>

const D1ReadReplicationModeDisabled D1ReadReplicationMode = "disabled"

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20read_replication%20%3E%20(property)%20mode%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20read_replication%20%3E%20(property)%20mode">Link to this property</a>

</details>

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20read_replication">Link to this property</a>

UUID stringOptional

D1 database identifier (UUID).

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20uuid">Link to this property</a>

Version stringOptional

<a href="#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)%20%3E%20(property)%20version">Link to this property</a>

</details>

[Link to this property](<#(resource)%20d1%20%3E%20(model)%20d1%20%3E%20(schema)>)

### Create D1 Database

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/d1"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  d1, err := client.D1.Database.New(context.TODO(), d1.DatabaseNewParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    Name: cloudflare.F("my-database"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", d1.UUID)
}
```

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "created_at": "2022-11-15T18:25:44.442097Z",
    "file_size": 12,
    "jurisdiction": "eu",
    "name": "my-database",
    "num_tables": 12,
    "read_replication": {
      "mode": "auto"
    },
    "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "version": "production"
  },
  "success": true
}
```

##### Returns Examples

200 example

```
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "created_at": "2022-11-15T18:25:44.442097Z",
    "file_size": 12,
    "jurisdiction": "eu",
    "name": "my-database",
    "num_tables": 12,
    "read_replication": {
      "mode": "auto"
    },
    "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "version": "production"
  },
  "success": true
}
```