I’m following a tutorial on NestJS and it uses Docker to deploy the database (locally). I’m totally new with Docker by the way.
As an ORM, it uses Prisma.
My Docker container launches, "ready to accept connections", but when I do npx prisma migrate dev
, it returns ->
Error: P1001: Can’t reach database server at
localhost
:5434
Please make sure your database server is running atlocalhost
:5434
.
Here’s the DATABASE_URL situated in a .env file (I added the connect_timeout after some searches on internet but it didn’t solve the problem) :
DATABASE_URL="postgresql://postgres:123@localhost:5434/nest?schema=public?connect_timeout=300"
Here’s my docker-compose.yml :
docker-compose.yml
2
Answers
The postgres default port is 5432, not 5431. Try to change it in docker-compose.yml
I am following the same tutorial. I had this error as well.
I fixed it by simply deleting the migrations folder inside the prisma folder and then run
npx prisma migrate dev
again.migrations
folder inside theprisma
foldernpx prisma migrate dev
What I noticed is that, the error is caused by this command
db:dev:rm": "docker compose rm dev-db -s -f -v
in yourpackage.json
I don’t know why though but you may need to avoid using it.
I hope this is helpful.