> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vertracloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Database to Stack

> Creates a database already inside a stack and connects it to the applications you choose.

Creates a database inside the stack and connects it to the applications you list. The database counts against your plan like any other, with the same limits as [Create Database](https://docs.vertracloud.app/api-reference/endpoint/databases/create.md). Needs the `stacks:write` scope when called with an API key.

The same body works on `POST https://api.vertracloud.app/v1/apps/{id}/stack/databases`, which starts from an application. When that application is **not in a stack**, the call also creates the stack, named by `stack_name`.

**stack\_id** `string` *required*

The stack ID. On `/v1/apps/{id}/stack/databases`, the path has the application ID instead.

**workspace\_id** `string`

The workspace the stack belongs to, when you act on it as the workspace owner.

**type** `string` *required*

The database engine.

**name** `string` *required*

The database name.

**ram** `integer` *required*

Memory in MB.

**version** `string`

The engine version.

**description** `string | null`

Optional description.

**bindings** `object[]`

The applications to connect it to. Each item has `app_id` and an optional `env_map` (see [Create Stack Connection](https://docs.vertracloud.app/api-reference/endpoint/stacks/bindings/create.md)).

**stack\_name** `string`

Only for `POST /v1/apps/{id}/stack/databases` on an application that is not in a stack: the name of the stack that is created.

### Response

**response** `object`

`201`.

**Toggle object**

**stack** `object`

The stack, as in [Get Stack](https://docs.vertracloud.app/api-reference/endpoint/stacks/get.md).

**database\_id** `string`

The ID of the new database.

**restart\_required** `boolean`

`true` when an application must restart to read the new variables and certificates.

**apps\_to\_restart** `string[]`

The applications that need a restart.

### Errors

| Status | Code | When |
| - | - | - |
| 403 | `MAX_DATABASES_REACHED` | The plan's database limit was reached. |
| 403 | `INSUFFICIENT_MEMORY` | Not enough free memory in the plan for the database. |
| 400 | `INVALID_DATABASE_VERSION` | The version does not exist for the engine. |
| 409 | `STACK_MEMBER_CONFLICT` | The application is already in another stack. |
| 403 | `WORKSPACE_OWNER_ONLY` | You are a workspace member, not the owner. |
| 404 | `STACK_NOT_FOUND` | The stack does not exist or belongs to another account. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.