# DATABASE_DISABLED

<!-- Generated by docs/modules/diagnostics from the package catalogs. Write a guide in docs/diagnostics/<CODE>.md instead of editing this file. -->

A query on `db`, or on `useDatabase('default').db`, throws `DATABASE_DISABLED`. Code reads the Default Database, but the runtime has no Default Database.

## Why it happens

The generated Database registry has no `default` entry. ViteHub then gives the Default Database a placeholder that throws on first use. This occurs when:

- The app has only Named Databases, such as `server/databases/analytics.ts`. No Database is named `default`. The Agent `db()` Capability without a `database` option also reads `default`.
- An app that uses `@vite-hub/database` alone passes `false` to `hubDatabase()`. The registry is then empty.

With `vitehub()`, a disabled Database fails earlier. The build stops with `VITE_HUB_B0013` when code imports accessors from `vite-hub/database`. An enabled Vite Database without a Definition always has an empty Default Database.

Some generated runtimes report a missing Default Database as [`DATABASE_NOT_FOUND`](https://vitehub.dev/docs/database/diagnostics/database_not_found) for `default`. Examples are the Nuxt module and hosted Cloudflare and Vercel builds.

## Fix it

```diff [server/api/events.get.ts]
 import { useDatabase } from 'vite-hub/database'

 export default defineEventHandler(() => {
-  const { db, schema } = useDatabase('default')
+  const { db, schema } = useDatabase('analytics')
   return db.select().from(schema.events)
 })
```

Use the name of the Named Database that has the tables. For an Agent, set `db({ database: 'analytics' })`. If the app needs one database only, use a Default Database instead: `server/databases/default.ts`.

```diff [vite.config.ts]
 export default defineConfig({
-  plugins: [hubDatabase(false)],
+  plugins: [hubDatabase()],
 })
```

Remove `false` when you register `hubDatabase()` directly. With `vitehub()`, set `database: true`.

## Check the fix

Run `vitehub inspect definitions --kind database`. The list must contain the name that the code uses. Then restart `vite dev` and call the route again.

## Related

- [Define a database](https://vitehub.dev/docs/database/configure#define-a-database)
- [Use Named Databases](https://vitehub.dev/docs/database/server-api#use-named-databases)
- [Enable Database](https://vitehub.dev/docs/database/get-started#enable-database)
- [Database Capability options](https://vitehub.dev/docs/database/agent-capability#options)
- [`DATABASE_NOT_FOUND`](https://vitehub.dev/docs/database/diagnostics/database_not_found)
- [`DATABASE_MIXED_DEFINITIONS`](https://vitehub.dev/docs/database/diagnostics/database_mixed_definitions)

## Source

`DATABASE_DISABLED` belongs to the `database` package. Its catalog entry is in [`src/error-diagnostics.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/database/src/error-diagnostics.ts#L128). It is raised in [`src/runtime/drizzle-runtime.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/database/src/runtime/drizzle-runtime.ts#L29).

See [all Database diagnostics](https://vitehub.dev/docs/database/diagnostics).

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/database.md)
- [Get started](https://vitehub.dev/raw/docs/database/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/database/configure.md)
- [Server API](https://vitehub.dev/raw/docs/database/server-api.md)
- [Agent capability](https://vitehub.dev/raw/docs/database/agent-capability.md)
- [Hosts](https://vitehub.dev/raw/docs/database/hosts.md)
- [Limits and errors](https://vitehub.dev/raw/docs/database/limits-and-errors.md)

Next: [DATABASE_INVALID_D1_HTTP_URL](https://vitehub.dev/raw/docs/database/diagnostics/database_invalid_d1_http_url.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
