skip to Main Content

api git:(main) ✗ pnpm prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "localhost:2010"

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

Please make sure to provide valid database credentials for the database server at localhost.enter image description here

Here’s the code of my docker-compose.yml file:

version: '3.8'

services:
  db:
    container_name: parkngo_db
    image: postgres
    restart: always
    ports:
      - 2010:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
      POSTGRES_PASSWORD: passcode
    volumes:
      - db_data_parkngo:/var/lib/postgresql/data
volumes:
  db_data_parkngo:

The code of my .env file :

DATABASE_URL="postgresql://postgres:passcode@localhost:2010/postgres?schema=public"

and finally schema.prisma file:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  uid          String        @id
  createdAt    DateTime      @default(now())
  updatedAt    DateTime      @updatedAt

  name         String?
  
  Credentials  Credentials?
  AuthProvider AuthProvider?
  Admin        Admin?
}
// other models

Things I’ve already done:

  1. .env is in correct location
  2. docker is running in correct port (2010)
  3. postgres is running fine (port 2010 -> port 5432 (inside docker))

Apart from this prisma generate and studio command can be executed but obviously you can’t add records on it.

2

Answers


  1. Chosen as BEST ANSWER

    After trying almost everything, I thought to start over and surprisingly after removing all my containers and creating new ones resolved the problem.

    Here are the commands for stopping running containers:

    docker stop $(docker ps -aq)
    

    For removing all containers:

    docker rm $(docker ps -aq)
    docker rmi $(docker images -q)  # Optionally, remove all images
    docker network prune           # Remove all unused networks
    

  2. Are you sure you’re connecting to the correct postgres instance?

    What if you try changing the connection-url to:

    DATABASE_URL="postgresql://postgres:passcode@parkngo_db:2010/postgres?schema=public"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search