Prisma:验证数据源“db”时出错:URL 必须以协议“postgresql://”或“postgres://”开头

Ali*_*ia 11 prisma

我正在尝试在生产中使用 prisma 部署我的 NestJS 应用程序。但是当启动我的服务器时,我遇到了这个错误:

nestjs     | PrismaClientInitializationError: error: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://`.
nestjs     |   -->  schema.prisma:11
nestjs     |    | 
nestjs     | 10 |   provider          = "postgresql"
nestjs     | 11 |   url               = env("DATABASE_URL")
nestjs     |    | 
nestjs     | 
nestjs     | Validation Error Count: 1
nestjs     |     at Object.loadEngine (/app/node_modules/@prisma/client/runtime/index.js:35591:19)
nestjs     |     at async Object.instantiateLibrary (/app/node_modules/@prisma/client/runtime/index.js:35520:5)
nestjs     |     at async Object.start (/app/node_modules/@prisma/client/runtime/index.js:35670:5)
nestjs     |     at async Proxy.onModuleInit (/app/dist/prisma.service.js:14:9)
nestjs     |     at async Promise.all (index 0)
nestjs     |     at async callModuleInitHook (/app/node_modules/@nestjs/core/hooks/on-module-init.hook.js:43:5)
nestjs     |     at async NestApplication.callInitHook (/app/node_modules/@nestjs/core/nest-application-context.js:178:13)
nestjs     |     at async NestApplication.init (/app/node_modules/@nestjs/core/nest-application.js:96:9)
nestjs     |     at async NestApplication.listen (/app/node_modules/@nestjs/core/nest-application.js:155:33)
nestjs     |     at async bootstrap (/app/dist/main.js:8:5) {
nestjs     |   clientVersion: '3.11.1',
nestjs     |   errorCode: 'P1012'
nestjs     | }
Run Code Online (Sandbox Code Playgroud)

我的 docker-compose.yml :

version: "3.2"

services:
  nestjs:
    container_name: nestjs
    build:
      context: ./apps/nestjs
      dockerfile: Dockerfile.prod
    env_file:
      - ./apps/nestjs/.env
Run Code Online (Sandbox Code Playgroud)

我的.env:

DATABASE_URL="postgres://myUser:myPassword@myHost:myPort/myDB?sslmode=require"
Run Code Online (Sandbox Code Playgroud)

我尝试做的事情:

  1. 检查我的是否.env已被考虑在内。当我进入容器时,我的环境变量就存在
  2. 尝试替换postgrespostgresql

有任何想法吗?

感谢您!

Ali*_*ia 23

问题解决了。

我不必在 .env 中用 " 将 URL 括起来。