Next.js Discord

Discord Forum

Prisma duplicate ID

Unanswered
Rough harvester ant posted this in #help-forum
Open in Discord
Avatar
Rough harvester antOP
model SplitResponse {
  id      String   @id @default(auto()) @map("_id") @db.ObjectId
  text    String
  active  Boolean
  message Message?

  @@map("split_responses")
}

 const newMsgsForCreatingLessonState = newMessages.map(nm => {
            if (nm.hasOwnProperty('splitResponse')) {
                return { splitResponse: { create: { active: nm.splitResponse?.active, text: nm.splitResponse?.text } }, role: nm.role, }
            }
            else {
                return { content: nm.content, role: nm.role }
            }
        })
        const lessAndState = await prisma.$transaction(async (tx) => {
            const lessonState = await tx.lessonState.create({
                data: {
                    messages: {
                        create: [{
                            content: newQuestion,
                            role: "user"
                        },
                        ...newMsgsForCreatingLessonState]
                    },
                    ...


Invalid `prisma.lessonState.create()` invocation:


Unique constraint failed on the constraint: `messages_splitResponseId_key`


I'm getting this error... but the ID key for splitResponse is auto generated as shown in the schema above? Is this a bug?

0 Replies