Prisma cannot authenticate database server

Viewed 4158

I'm using docker to initiate a postgres db:

version: '3.8'
services:
  postgres:
    image: postgres:13
    restart: always
    environment:
      POSTGRES_USER: db_user
      POSTGRES_PASSWORD: db_password
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - '5432:5432'
volumes:
    postgres:

and in my /.env file I have:

DATABASE_URL="postgresql://db_user:db_password@localhost:5432/college_db?schema=public"

I start docker:

PS C:\Users\alucardu\Documents\projects\**-react> docker-compose up -d
Starting **-react_postgres_1 ... done

Check if the server is running:

PS C:\Users\alucardu\Documents\projects\**-react> docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS          PORTS                                       NAMES
e0f9233ce34b   postgres:13   "docker-entrypoint.s…"   2 minutes ago   Up 33 seconds   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   **-react_postgres_1

But when I run a Prisma migrate I get an authentication error:

PS C:\Users\alucardu\Documents\projects\movieseat-react> npx prisma migrate dev --name "init"
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "college_db", schema "public" at "localhost:5432"

Error: P1000: Authentication failed against database server at `localhost`, the provided database credentials for `db_user` are not valid.

Please make sure to provide valid database credentials for the database server at `localhost`.

Why is Prisma not matching the set db_user and db_password to the environment variables created in the docker yml?

//edit.

I've added a college_db database and a superuser called db_user and made it owner of the college_db:

enter image description here

But I'm still getting the same error.

3 Answers

What-a-mistaka-to-make. I had postgres installed locally on my Windows machine. So it was using that instance of postgres instead of the one on my docker environment. I removed the windows postgres installation and everything is working as expected. https://github.com/prisma/prisma/issues/8927

I think the issue is a database name mismatch.

Try adding POSTGRES_DB: college_db environment variable to your postgres container.

By default the init container uses POSTGRES_USER value for the database name.

Try to remove the quote from the port and edit to match below


version: '3.8'
services:
  postgres:
    image: postgres:13
    restart: always
    environment:
      POSTGRES_USER: db_user
      POSTGRES_PASSWORD: db_password
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - 5432:5432
volumes:
    postgres:

OR


ersion: '3.8'
services:
  postgres:
    image: postgres:13
    restart: always
    environment:
      POSTGRES_USER: db_user
      POSTGRES_PASSWORD: db_password
    volumes:
      - postgres:/var/lib/postgresql/data
    expose:
      - 5432
    ports:
      - 5432
volumes:
    postgres:
Related