Zain Malik
Zain Malik

Reputation: 1

PrismaClientValidationError: Invalid prisma.<Model>.create() invocation

My prisma schema for the issue is:

model User {
  id                   String       @id @default(uuid())
  email                String       @unique
  .
  .
  .
  TransactionComment         TransactionComment[]
  TransactionConnectNote     TransactionConnectNote[]
  HighlightPostFeatureStatus HighlightPostFeatureStatus[]
}

model TransactionComment {
  id                String     @id @default(uuid())
  ...
  ...
  ...
  user              User       @relation(fields: [userId], references: [id])
  userId            String
  date              DateTime   @default(now())
  tone              String?

  @@index([userId])
}

I am creating a TransactionComment using this code:

await prisma.TransactionComment.create({
        data: {
          chosenPlan: req.body.chosenPlan,
          promptRequest: req.body.prompt,
          promptResponse: req.body.promptResponse,
          postText: req.body.postText,
          postID: req.body.postId,
          tokenPrompt: req.body.tokenPrompt,
          tokenCompletion: req.body.tokenCompletion,
          totalTokens: req.body.totalTokens,
          price: price,
          transactionSource: req.body.transactionSource,
          subscriptionID: req.body.subscriptionID,
          tone: req.body.tone,
          user: {
            connect: {
              id: req.user.userId,
            },
          },
          userId: req.user.userId,
        },
      });

Using the above code leads to the error saying:

Unknown arg userId in data.userId for type TransactionCommentCreateInput where

type TransactionCommentCreateInput {
  id?: String
  chosenPlan: ChosenPlan
  promptRequest: String
  promptResponse: String
  postText: String
  postID?: String | Null
  tokenPrompt?: Int | Null
  tokenCompletion?: Int | Null
  totalTokens?: Int | Null
  price?: Float | Null
  transactionSource?: String | Null
  subscriptionID?: String | Null
  date?: DateTime
  tone?: String | Null
  user: UserCreateNestedOneWithoutTransactionCommentInput
}

while after commenting userId I get the error: Argument userId is missing.

I have checked for spelling mistakes and checked the types as well. There are two types for any createInput one is createChecked and one is createUnchecked and both of these types are like how they are for other models in the client i.e. there's no anomaly. I have also deleted node_modules and reinstalled it deleting the cache along. I also regenerated the Prisma client multiple times to fix the issue but of no use. This code was working fine previously with the create function as follows:

await prisma.TransactionComment.create({
        data: {
          chosenPlan: req.body.chosenPlan,
          promptRequest: req.body.prompt,
          promptResponse: req.body.promptResponse,
          postText: req.body.postText,
          postID: req.body.postId,
          tokenPrompt: req.body.tokenPrompt,
          tokenCompletion: req.body.tokenCompletion,
          totalTokens: req.body.totalTokens,
          price: price,
          transactionSource: req.body.transactionSource,
          subscriptionID: req.body.subscriptionID,
          userId: req.user.userId,
          tone: req.body.tone,
        },
      });

Has anyone else faced it? Plus how can I fix it?

Getting type error while creating a record for TransactionComment table.

Upvotes: 0

Views: 434

Answers (0)

Related Questions