-
@janpio After upgrading to 4.6.0, we started reciving the following error when migrating our database: Error: Schema validation error - Error (query-engine-node-api library)
Error code: P1012
error: Error parsing attribute "@relation": The `onDelete` referential action of a relation must not be set to `SetNull` when a referenced field is required.
Either choose another referential action, or make the referenced fields optional.
--> schema.prisma:126
|
125 |
126 | survey Survey @relation(fields: [surveyId], references: [id], onDelete: SetNull)
127 |
| To rectify this, we changed the Our current database model: model Survey {
id String @id @default(cuid())
name String
survey Json
reportSurvey SurveyReport[]
...
}
model SurveyReport {
id String @id @default(cuid())
surveyId String
survey Survey @relation(fields: [surveyId], references: [id], onDelete: SetNull)
reportType SurveyReportType
...
} The output from the new migration: -- DropForeignKey
ALTER TABLE "SurveyReport" DROP CONSTRAINT "SurveyReport_surveyId_fkey";
-- AddForeignKey
ALTER TABLE "SurveyReport" ADD CONSTRAINT "SurveyReport_surveyId_fkey" FOREIGN KEY ("surveyId") REFERENCES "Survey"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
Beta Was this translation helpful? Give feedback.
Answered by
janpio
Nov 10, 2022
Replies: 1 comment
-
Continued here: #16228 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vladi-stevanovic
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Continued here: #16228