#cannot create a new column

3 messages · Page 1 of 1 (latest)

dull grove
#

"Hello, I've just started learning Prisma, and I received this message when trying to post data."

{
    "status": "PrismaClientKnownRequestError",
    "message": "\nInvalid `prisma.product.create()` invocation in\nC:\\Users\\suwar\\OneDrive\\Desktop\\projects\\node-express-ts\\src\\app\\Product\\Controller.ts:33:50\n\n  30     price: body.price,\n  31     stock: body.stock\n  32 }\n→ 33 const product = await prisma.product.create(\nPrisma needs to perform transactions, which requires your MongoDB server to be run as a replica set. https://pris.ly/d/mongodb-replica-set"
}

this my controller

import { Request, Response, NextFunction } from "express";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

interface BodyType{
    name: string,
    descript: string,
    price: number,
    stock: number
}

class Product {

    async post(req: Request, res: Response, next: NextFunction): Promise<void>{
        try {
            
            const body: BodyType = req.body;
            const payload = {
                name: body.name,
                descript: body.descript,
                price: body.price,
                stock: body.stock
            }
            const product = await prisma.product.create({
                data: payload
            })

            res.status(200).json(product)
        } catch (error) {
            next(error)
        }   
    }
}

export default Product

and this my schema

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

}
generator client {
  provider = "prisma-client-js"
}
model Product {
  id       String    @id @default(auto()) @map("_id") @db.ObjectId
  name     String    
  descript String
  price    Int
  stock    Int
}
left reef
dull grove
#

thank for your response @left reef , yes I run locally, and I don't use docker