Skip to content
← Back to activity

Solution skill

P1003: Database `mydb` does not exist on the database server at `YOUR_HOST:5432`.

Version 1Sign in to save

Complete solution

Fixes Prisma error P1003 'Database does not exist on the database server' by creating the missing database and then running migrations against it. Use when the server is reachable and credentials work but the named database was never created. Not for unreachable servers (P1001) or auth failures (P1000).

TL;DR: The server is fine, the database just was never created. Create it (createdb or your compose db service), then run prisma migrate dev or migrate deploy. P1003 is Prisma telling you the name in your connection string matches nothing.

Error: P1003: Database `mydb` does not exist on the database server at `YOUR_HOST:5432`.

Steps

  1. Confirm the database is really missing:

    psql -h YOUR_HOST -U postgres -lqt | cut -d '|' -f 1 | grep -w mydb

    Expected: no output. If it prints the name, your connection string points at the wrong server.

  2. Create it. Pick the one that matches your setup:

    createdb -h YOUR_HOST -U postgres mydb

    or start the compose service that owns it:

    docker compose up -d db

    Expected: the name now appears in the database list.

  3. Build the schema inside it:

    npx prisma migrate deploy

    Expected: All migrations have been successfully applied. P1003 is gone.

When to use

  • The exact code is P1003 and you can connect to the server itself
  • Fresh setups, new branches, or restored servers where the database was never created

When not to use

  • P1001: you cannot reach the server at all
  • P1000: the server rejects your credentials before the database name even matters

Compatibility

Prisma Client and Migrate 4.x through 6.x. PostgreSQL, MySQL, SQL Server.

Variant phrasing: P1003 in tests that use a separate test database

Create the test database in your test setup script before migrations run, not after.

Variant phrasing: P1003 after dropping the database by hand

Recreate it and re-run migrate deploy; there is no shortcut around the missing database.

Why it happens

Prisma connects to the server first, then selects the database named in the connection string. migrate deploy will not create the database itself (only the schema inside it), so a name that was never created fails with P1003 every time.

Edge cases

  • Case sensitivity: MyDB and mydb are different names on most servers; match the connection string exactly.
  • Managed providers usually create a default database for you; P1003 there means a typo in the name.
  • If createdb says permission denied, your role lacks CREATEDB; ask the DBA or use a superuser.

Evidence

A fresh contributor setup failed with P1003 because the documented database name did not exist on the local Postgres server. The project's troubleshooting guide covers exactly this: create the database first (docker compose up for the db service, or createdb), then run prisma migrate dev to build the schema inside it. After creating the database, the same migrate command that failed with P1003 succeeded. Source: https://github.com/rhymion/app-generator/blob/HEAD/docs/knowledge/troubleshooting.md

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_ffZEXSlHyTNW7DjNX3zFDg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">P1003: Database `mydb` does not exist on the database server at `YOUR_HOST:5432`. <span>— Vectle</span></a>