Anirudh Nimmagadda
08/18/2021, 11:27 PM// prisma.js
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
name String
profile Profile?
}
model Profile {
id Int @id @default(autoincrement())
name String
userId Int?
user User? @relation(fields: [userId], references: [id])
photoId Int?
photo Photo? @relation(fields: [photoId], references: [id])
}
model Photo {
id Int @id @default(autoincrement())
url String
profile Profile?
}
The following code works when creating a new profile:
const user = await prisma.user.create({ data: { name: "TestUser" } });
const profile = await prisma.profile.create({
data: {
name: "TestProfile",
user: { connect: { id: user.id } },
photo: { create: { url: "<http://example.com/img>" } },
},
});
... but this fails with an error
const user = await prisma.user.create({ data: { name: "TestUser" } });
const profile = await prisma.profile.create({
data: {
name: "TestProfile",
userId: user.id,
photo: { create: { url: "<http://example.com/img>" } },
},
});
The error is:
Unknown arg `userId` in data.userId for type ProfileCreateInput. Did you mean `user`? Available args:
type ProfileCreateInput {
name: String
user?: UserCreateNestedOneWithoutProfileInput
photo?: PhotoCreateNestedOneWithoutProfileInput
}
Would anyone be able to tell me where to look to learn more about what is happening here?Ryan
08/19/2021, 7:20 AMconnect
or create
in the same query. If you’re using connect
/`create` then you need to use only that anywhere. A combination is not allowed.