why can't create data with spread operator #23966
Replies: 2 comments
-
Hi @febrimaulana 👋 The error message indicates that there's a mismatch between the data you're trying to insert and the prisma schema for the purchaseOrder model. Specifically, the error points out that the data object you're using in the spread operator Can you please share your schema so I can attempt a reproduction? |
Beta Was this translation helpful? Give feedback.
-
I have a similar problem @ludralph prisma version: 5.13.0 Schema generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
model Account {
id String @id @default(cuid())
userId String @map("user_id")
type String
provider String
providerAccountId String @map("provider_account_id")
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
password String?
image String?
accounts Account[]
}
model VerificationToken {
id String @id @default(cuid())
email String
token String @unique
expires DateTime
@@unique([email, token])
}
model TableAccount {
id String @id @default(cuid())
screenName String?
userId String?
oauthToken String?
oauthTokenSecret String?
keyword String?
configuration String?
today Int?
yesterday Int?
total Int?
} And i am executing a function: export async function createTwitterAcc(params: any) {
const { newToken } = params;
console.log(newToken);
const { screen_name, user_id, oauth_token, oauth_token_secret } = newToken;
try {
const user = await db.tableAccount.create({
data: {
screenName: screen_name,
userId: user_id,
oauthToken: oauth_token,
oauthTokenSecret: oauth_token_secret,
today: 0,
yesterday: 0,
total: 0,
keyword: "keyword",
configuration: "configuration prompt",
},
});
console.log({ user });
} catch (error) {
console.log("Prisma", error);
}
} Error: Prisma PrismaClientValidationError:
Invalid `prisma.tableAccount.create()` invocation:
{
data: {
screenName: "RiseWithSobin",
userId: "153465446",
~~~~~~
oauthToken: "xxxxxxx-xxxxxx",
oauthTokenSecret: "xxxxxxxxxx",
today: 0,
yesterday: 0,
total: 0,
keyword: "keyword",
configuration: "configuration prompt",
? id?: String
}
}
Unknown argument `userId`. Available options are marked with ?.
at Tn (/home/sojin/Desktop/projects/learn/nextjs/authentication/node_modules/@prisma/client/runtime/library.js:115:6855)
at In.handleRequestError (/home/sojin/Desktop/projects/learn/nextjs/authentication/node_modules/@prisma/client/runtime/library.js:122:6510)
at In.handleAndLogRequestError (/home/sojin/Desktop/projects/learn/nextjs/authentication/node_modules/@prisma/client/runtime/library.js:122:6188)
at In.request (/home/sojin/Desktop/projects/learn/nextjs/authentication/node_modules/@prisma/client/runtime/library.js:122:5896)
at async l (/home/sojin/Desktop/projects/learn/nextjs/authentication/node_modules/@prisma/client/runtime/library.js:127:11167)
at async createTwitterAcc (webpack-internal:///(action-browser)/./app/lib/actions.ts:235:22)
at async /home/sojin/Desktop/projects/learn/nextjs/authentication/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:39:418
}
Trying to figure this out, could you help me out please |
Beta Was this translation helpful? Give feedback.
-
Bug description
I have a json request like this example
When I want to insert with the spread operator like the code below it always produces an error
but if i like this it works
even though the body data has been validated with DTO and the fields and data types are all the same
here is the error
How to reproduce
Expected behavior
No response
Prisma information
// Add your schema.prisma
// Add your code using Prisma Client
Environment & setup
Prisma Version
Beta Was this translation helpful? Give feedback.
All reactions