PrismaP
Prisma7mo ago
11 replies
cap.MacTavish

Prisma database name overwritten with localhost IP

I am new to prisma and have no idea how to fix this problem, an unusual issue:

export const prisma = remember('prisma', () => {
  const connectionString = ${process.env.DATABASE_URL};
  const adapter = new PrismaPg({ connectionString });

  const client = new PrismaClient({
    adapter,
  });
  void client.$connect();
  return client;
});


when I run npx prisma migrate deploy, DB is migrated and the tables are created. but when I run the app, the client gives me following error: User was denied access on the database localhost. Error: P1010. With the same connection url string for client and migration, why the client is using localhost?

In prisma debug mode the logs are following, despite correct connectionString in adapter somehow the database name is overwritten with localhost IP

PrismaPgAdapterFactory {
  provider: 'postgres',
  adapterName: '@prisma/adapter-pg',
  config: {
    connectionString: 'postgresql://test:<redacted-password>@<db-url>:5432/test?schema=test\n'
  },
  options: undefined
}

prisma:client:request_handler {
  "code": "P1010",
  "meta": {
    "database_name": "<container_ip>"
  },
  "clientVersion": "6.7.0",
  "name": "PrismaClientKnownRequestError"
}


I manually ran npx prisma generate in the container, it found the env variables and loaded them and it did its job. Then I tried to run the client, the output was:

prisma:tryLoadEnv Environment variables not found at null +8ms
prisma:tryLoadEnv Environment variables loaded from /app/.env +1ms
postgresql://test:<redacted-password>@<db-url>:5432/test?schema=test


and then the error still persists: User was denied access on the database <container_ip>
Was this page helpful?