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
:
But I'm still getting the same error.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With