I’m encountering an error while testing my API in Postman. The error occurs when I try to create a new record in the etl_users_project table using Prisma. Here is the code snippet and the error message:
Invalid `prisma.etl_users_project.create()` invocation:
{
data: {
user_name: "Arun",
project_code: "BIS",
~~~~~~~~~~~~
etl_projects: {
connect: {
project_code: "BIS"
}
},
etl_user_master: {
connect: {
id: 10
}
},
? crt_dtm?: DateTime | Null,
? crt_user_id?: String | Null,
? updt_dtm?: DateTime | Null,
? updt_user_id?: String | Null
}
}
Unknown argument `project_code`. Available options are marked with ?.
at Dn (C:UsersmendrevDownloadsBISWebAppZipBISWebBackendnode_modules@prismaclientruntimelibrary.js:114:8082)
at Mn.handleRequestError (C:UsersmendrevDownloadsBISWebAppZipBISWebBackendnode_modules@prismaclientruntimelibrary.js:121:7396)
at Mn.handleAndLogRequestError (C:UsersmendrevDownloadsBISWebAppZipBISWebBackendnode_modules@prismaclientruntimelibrary.js:121:7061)
at Mn.request (C:UsersmendrevDownloadsBISWebAppZipBISWebBackendnode_modules@prismaclientruntimelibrary.js:121:6745)
at async l (C:UsersmendrevDownloadsBISWebAppZipBISWebBackendnode_modules@prismaclientruntimelibrary.js:130:9633)
at async saveUserProject (file:///C:/Users/mendrev/Downloads/BISWebAppZip/BISWeb/Backend/controllers/etl_UserProjectNew.js:32:32) {
clientVersion: '5.21.1'
}
What I’ve Tried:
Verified that project_code is correctly defined in the Prisma schema.
Checked the relationships and connections in the schema.
Ensured that the Prisma Client is up to date.
Schema Snippet:
Here is the relevant part of my Prisma schema:
Schema Prisma:
model etl_user_master {
id Int @id @default(autoincrement())
network_id String @db.VarChar(50)
name String @db.VarChar(100)
email String @unique @db.VarChar(100)
enabled Boolean? @default(true)
etl_users_project etl_users_project?
}
model etl_projects {
project_code String @id @db.VarChar(100)
project_name String @db.VarChar(100)
owner String? @db.VarChar(100)
owner_email String? @db.VarChar(100)
secondaryOwner String? @db.VarChar(100)
secondary_owner_email String? @db.VarChar(100)
start_date DateTime? @db.Date
enable Boolean?
crt_dtm DateTime? @db.Timestamp(6)
crt_user_id String? @db.VarChar(20)
updt_dtm DateTime? @db.Timestamp(6)
updt_user_id String? @db.VarChar(20)
etl_users_project etl_users_project[]
}
model etl_users_project {
uid Int @id @default(autoincrement())
user_name String @db.VarChar(100)
project_code String @db.VarChar(100)
crt_dtm DateTime? @db.Timestamp(6)
crt_user_id String? @db.VarChar(20)
updt_dtm DateTime? @db.Timestamp(6)
updt_user_id String? @db.VarChar(20)
etl_projects etl_projects @relation(fields: [project_code], references: [project_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_project_code")
etl_user_master etl_user_master @relation(fields: [uid], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_user_id")
}
Why am I getting this error, and how can I resolve it? Any help would be greatly appreciated
My React Js Backend Code :
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
// Save User and Project Code
const saveUserProject = async (req, res) => {
const { user_name, project_code } = req.body;
try {
if (!user_name || !project_code) {
return res.status(400).json({ msg: 'User name and project code are required' });
}
// Find the user by name
const user = await prisma.etl_user_master.findFirst({
where: { name: user_name }
});
if (!user) {
return res.status(404).json({ msg: 'User not found' });
}
// Ensure the project exists
const project = await prisma.etl_projects.findUnique({
where: { project_code: project_code }
});
if (!project) {
return res.status(404).json({ msg: 'Project not found' });
}
// Create the user project
const newUserProject = await prisma.etl_users_project.create({
data: {
user_name: user_name,
project_code: project_code,
etl_projects: {
connect: { project_code: project_code }
},
etl_user_master: {
connect: { id: user.id }
}
}
});
res.json({ status: 'success', data: newUserProject });
} catch (error) {
console.error(error);
res.status(500).json({ msg: 'Internal Server Error' });
}
};
export {
saveUserProject,
};