1

I'm encountering a persistent P1000 Authentication Failed error when trying to connect Prisma to a PostgreSQL database running in Docker. Despite having correct credentials and a running container, Prisma migrations fail with authentication errors.

File Structure

ecomm/
├── prisma/
│   └── schema.prisma
├── src/
│   ├── generated/           # (if using custom Prisma output)
│   ├── bin.ts
│   ├── index.ts
│   └── db.ts
├── dist/                    # (generated after build)
│   ├── bin.js
│   ├── index.js
│   └── db.js
├── node_modules/
├── .env
├── .gitignore
├── package.json
├── package-lock.json
├── tsconfig.json
└── README.md

package.json:

{
  "name": "ecomm",
  "version": "1.0.0",
  "scripts": {
    "build": "prisma generate && tsc",
    "start": "node dist/bin.js",
    "dev": "ts-node src/bin.ts"
  },
  "type": "commonjs",
  "dependencies": {
    "@prisma/client": "^6.16.1",
    "express": "^5.1.0"
  },
  "devDependencies": {
    "@types/express": "^5.0.3",
    "@types/node": "^20.0.0",
    "prisma": "^6.16.1",
    "typescript": "^5.0.0",
    "ts-node": "^10.9.0"
  }
}

prisma schema

generator client {
  provider = "prisma-client-js"
  output   = "../src/generated/prisma"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
model Request{
  id Int @id @default(autoincrement())
  a  Int
  b  Int
  answer Int
  type Type
}

enum Type{
  ADD
  MUL
}

.env:

DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres"

Error Details Command that fails:

npx prisma migrate dev --name init

Error output:

Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "localhost:5432"
Error: P1000: Authentication failed against database server, the provided database credentials for `postgres` are not valid.
Please make sure to provide valid database credentials for the database server at the configured address.

Docker commands I've used:

# Start PostgreSQL container
docker run -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres

# Verify container is running
docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS                    NAMES
f1e171459a61   postgres   "docker-entrypoint.s…"   26 minutes ago   Up 26 minutes   0.0.0.0:5432->5432/tcp   sweet_chaplygin

What I've Tried

  1. Verified container is running - docker ps shows the container is up

  2. Double-checked credentials - Password matches in both Docker command and DATABASE_URL

  3. Tested different connection strings - Tried various formats with same result

  4. Restarted containers multiple times - Same error persists

  5. Checked for port conflicts - Port 5432 appears to be free

1
  • Having the same issue here right now! I can log in to the database from docker cli commands, but whenever i try to connect with a script, it won't let me. I have an inkling it's not an issue with Prisma, but instead with postgresql. The reason why i think that is that I ran a quick javascript with the "pg" library and it had the same issue! Commented Nov 3 at 1:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.