提问人:Vishal Bindal 提问时间:11/16/2023 最后编辑:Vishal Bindal 更新时间:11/16/2023 访问量:32
使用 Prisma 获取连接字符串错误
getting connection string error with prisma
问:
`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)db
prisma://
please anyone tell me how to rectify this error
答: 暂无答案
评论
PrismaClient
npx prisma generate