You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Prisma插入数据报错:Could not find mapping for model Product

Prisma插入数据报错:Could not find mapping for model Product

通过POST请求往Prisma关联的PostgreSQL表插入新数据时,触发如下映射错误:

C:\GitHub\Project\BackEnd\node_modules@prisma\client\runtime\index.js:30904
throw new Error(Could not find mapping for model ${model});
^
Error: Could not find mapping for model Product
at PrismaClient._executeRequest (C:\GitHub\Project\BackEnd\node_modules@prisma\client\runtime\index.js:30904:17)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async PrismaClient._request (C:\GitHub\Project\BackEnd\node_modules@prisma\client\runtime\index.js:30864:16)
at async createNew(C:\GitHub\Project\BackEnd\src\Controller\ProdutoController.ts:20:25) {
clientVersion: '4.3.1'
}
[nodemon] app crashed - waiting for file changes before starting...

Prisma Schema定义:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

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


model Product{
    id          Int      @id @default(autoincrement())
    name        String
    description String
    createDate  String
    datePublish DateTime @default(now())
    type        String
    value       Float
    height      String
    width       String
    length      String
    material    String
    category    String
}

调用Prisma创建数据的代码:

async createNew (req: Request, res: Response){
        const {
            name,           
            description ,      
            createDate,    
            datePublish ,  
            type,           
            value,          
            height,         
            width,        
            length,    
            material,
            category       
        } = req.body

        const product = await prisma.product.create({
            data:{
                name,           
                description ,      
                createDate,    
                datePublish ,  
                type,           
                value,          
                height,         
                width,        
                length,    
                material ,
                category
            },
        })


        
        return res.json({product})
}

解决方案
重新执行Schema迁移操作后错误修复。执行时Prisma提示无Schema变更,推测问题根源是Prisma客户端与PostgreSQL数据库之间的同步异常。

内容的提问来源于stack exchange,提问作者Thiago David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 02:55:23