how to fix schema or query for prisma

I have this part of the schema:
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
lastWorkspace Workspace @relation(fields: [lastWorkspaceId], references: [id])
lastWorkspaceId String @unique
Account Account[]
Session Session[]
}

model Workspace {
id String @id @default(cuid())
name String
userId String @unique
user User?
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
lastWorkspace Workspace @relation(fields: [lastWorkspaceId], references: [id])
lastWorkspaceId String @unique
Account Account[]
Session Session[]
}

model Workspace {
id String @id @default(cuid())
name String
userId String @unique
user User?
}
and when running this query:
prismaClient.user.create({
data: { ...data, lastWorkspace: { create: { name: workspaceName } } },
});
prismaClient.user.create({
data: { ...data, lastWorkspace: { create: { name: workspaceName } } },
});
I get this error:
'Invalid `prisma.user.create()` invocation:\n' +
'\n' +
'{\n' +
' data: {\n' +
' name: "alann",\n' +
' email: "[email protected]",\n' +
' image: "https://cdn.discordapp.com/embed/avatars/1.png",\n' +
' emailVerified: null,\n' +
' lastWorkspace: {\n' +
' create: {\n' +
` name: "alann's Workspace",\n` +
'+ userId: String\n' +
' }\n' +
' }\n' +
' }\n' +
'}\n' +
'\n' +
'Argument `userId` is missing.\n'
'Invalid `prisma.user.create()` invocation:\n' +
'\n' +
'{\n' +
' data: {\n' +
' name: "alann",\n' +
' email: "[email protected]",\n' +
' image: "https://cdn.discordapp.com/embed/avatars/1.png",\n' +
' emailVerified: null,\n' +
' lastWorkspace: {\n' +
' create: {\n' +
` name: "alann's Workspace",\n` +
'+ userId: String\n' +
' }\n' +
' }\n' +
' }\n' +
'}\n' +
'\n' +
'Argument `userId` is missing.\n'
I thought this query would pull the user id from the main query and inject it into the workspace creation query. halp?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server