I recently started using Next14, much like everyone else I would assume, and I am running into an error when trying to create a very simple object to push to my 'Decision' collection in the db. My server action clearly isn't looking for an id argument in the codebase, because it should be auto generated on the server's end with the @map() function in the Prisma Schema.
I am using: Next 14.0.1 Prisma 5.5.2 Shadcn UI
This is the error I am getting on form submission: error message
This is my schema:
model Pros {
id String @id @map("_id") @db.ObjectId
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
title String
weight Int
decision Decision? @relation(fields: [decisionId], references: [id])
decisionId String @map("decision")
}
model Cons {
id String @id @map("_id") @db.ObjectId
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
title String
weight Int
decision Decision? @relation(fields: [decisionId], references: [id])
decisionId String? @map("decision")
}
model Decision {
id String @id @map("_id") @db.ObjectId
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
title String
pros Pros[]
Cons Cons[]
}
this is my server action:
import prisma from "@/lib/prisma"
export const addDecision = async (formData) => {
await prisma.decision.create({
data: {
title: formData.get("title"),
},
})
}
And finally, this is the UI for the form:
'use client'
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { addDecision } from "@/lib/actions"
export default function AddDecision({ children }) {
return (
<Dialog>
<DialogTrigger>Open</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure absolutely sure?</DialogTitle>
<DialogDescription>
<form action={addDecision}>
<input name="title" placeholder="title" />
<input type="submit" value="Submit" />
</form>
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
)
}
I've tried: 1.) removing @map from the id in schema (Prisma hated that) 2.) adding const { title } = formData; right above the server action 3.) Pulling my non-existent hair out
If anyone can point me in the right direction, I will be very grateful.
Thanks!