使用 Prisma 获取连接字符串错误

getting connection string error with prisma

提问人:Vishal Bindal 提问时间:11/16/2023 最后编辑:Vishal Bindal 更新时间:11/16/2023 访问量:32

问:



`schema.prisma file`

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

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

model User {
  id       String  @id @default(auto()) @map("_id") @db.ObjectId
  name     String?
  email    String  @unique
  password String
  posts    Post[]
}

model Post {
  id       String @id @default(auto()) @map("_id") @db.ObjectId
  slug     String
  title    String
  body     String
  author   User   @relation(fields: [authorId], references: [id])
  authorId String @db.ObjectId
}


`prisma/index.js`
const { PrismaClient } = require('@prisma/client/edge');
require('dotenv').config();

const prisma = new PrismaClient({
  datasources: {
    db: {
      url: process.env.DATABASE_URL,
    },
  },
});

module.exports = prisma;


`.env connection string :` 
DATABASE_URL= mongodb+srv://username:[email protected]/?retryWrites=true&w=majority


我在使用 postman singup 时出错:Error: PrismaClientKnownRequestError: 无效调用:prisma.user.create()

验证数据源时出错:URL 必须以 exports.signup (D:\prisma_backend\controllers\userControllers.js:20:11) 中的协议开头 在 process.processTicksAndRejections (node:internal/process/task_queues:95:5)dbprisma://

please anyone tell me how to rectify this error

node.js mongoDB express prisma

评论

0赞 Nurul Sundarani 11/17/2023
您正在运行什么命令来生成?PrismaClient
0赞 Vishal Bindal 11/18/2023
npx prisma generate

答: 暂无答案