P
Prisma•2w ago
Shishigami

Relation missing in UncheckedCreateInput

I have this model:
model Configuration {
appId String @unique
predecessedById String? @unique
predecessedBy Configuration? @relation("PredecessedBy", fields: [predecessedById], references: [appId])
successedBy Configuration? @relation("PredecessedBy")
}
model Configuration {
appId String @unique
predecessedById String? @unique
predecessedBy Configuration? @relation("PredecessedBy", fields: [predecessedById], references: [appId])
successedBy Configuration? @relation("PredecessedBy")
}
and I would like to create a configuration like so:
db.configuration.create({
data: {
appId: '...',
predecessedBy: {
connect: {
appId: '...'
}
}
}
});
db.configuration.create({
data: {
appId: '...',
predecessedBy: {
connect: {
appId: '...'
}
}
}
});
However predecessedBy does not exist on the UncheckedCreateInput type, instead there is only successedBy. Why is that and what do I have to change? The Update type has both
2 Replies
Prisma AI Help
Prisma AI Help•2w ago
Skipping coffee for instant knowledge! Let's brew that AI answer now. The issue you're experiencing is related to how Prisma handles relations in its generated input types. When you use a connect or create operation in a Prisma query, Prisma automatically switches to "checked" mode for all relations in that query, which means you need to use the relational syntax consistently for all relations. In your case, the problem is that when you try to use predecessedBy in a create operation, it's not available in the UncheckedCreateInput type. This is because: 1. Prisma requires both sides of a relation to be present in the schema 2. When using relational operations like connect, you need to use the "checked" input type, not the "unchecked" one Looking at your schema, there's a potential issue with how your self-relation is defined. In a one-to-one self-relation, both sides need to reference the same relation name. In your schema, both predecessedBy and successedBy are using the same relation name "PredecessedBy", which might be causing confusion. Here's what you can try: 1. Make sure both sides of your relation use the same relation name but are properly defined:
model Configuration {
appId String @unique
predecessedById String? @unique
predecessedBy Configuration? @relation("ConfigurationHistory", fields: [predecessedById], references: [appId])
successedBy Configuration? @relation("ConfigurationHistory")
}
model Configuration {
appId String @unique
predecessedById String? @unique
predecessedBy Configuration? @relation("ConfigurationHistory", fields: [predecessedById], references: [appId])
successedBy Configuration? @relation("ConfigurationHistory")
}
2. After updating your schema, run prisma generate to regenerate the client types. 3. Then try your create operation again:
db.configuration.create({
data: {
appId: '...',
predecessedBy: {
connect: {
appId: '...'
}
}
}
});
db.configuration.create({
data: {
appId: '...',
predecessedBy: {
connect: {
appId: '...'
}
}
}
});
This issue is similar to what's described in several GitHub issues where users have encountered problems with relations not being properly recognized in create or update operations Github Issue #7093 and [Github Issue #5788](https://gith ub.com/prisma/prisma/issues/5788). The reason the update type has both relations while the create type doesn't might be because update inputs are fully optional (you can supply partial data), while create inputs have stricter requirements Github Issue #2839. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul•2w ago
Do you get any type errors? I don't get any errors when I try to use the model you have shared.
No description

Did you find this page helpful?