Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prisma cannot authenticate database server

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.

like image 935
Peter Boomsma Avatar asked Sep 11 '25 14:09

Peter Boomsma


2 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

like image 126
Peter Boomsma Avatar answered Sep 13 '25 03:09

Peter Boomsma


If you are still having this problem, check if you have postgres installed on the machine without docker and check if postgres is started on Windows and stop this process and try again

enter image description here

like image 26
Marcos Vinicius Avatar answered Sep 13 '25 04:09

Marcos Vinicius