prisma: Prisma lift error: ambiguous self-relation detected

I accidentally had an error in a data model definition, which lead to a self-referencing model (related should have been pointing to a different model B, and not to A ):

model A {
  id      String @default(cuid()) @id @unique
  name    String    
  related A[] 
}

With this data model:

  • the first invocation of prisma2 lift save/up was successful.
  • further invocations of prisma2 lift save/up failed silently. Debugging showed the error message "Ambiguous self relation detected."

Expected behaviour:

  1. at the first invocation of prisma2 lift save/up, report the "Ambiguous self relation detected." message, and prevent the creation of the ambiguous self relation.
  2. don’t fail silently, but actually display the error message

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@nhuesmann : Open a new one please 🙏

@mavilein I am still having this issue in prisma2@2.0.0-preview014, binary version: 188a379c9b8c6650e5812f9bdb7407d7b197692f. Preview 14 states it fixes this bug. Should I open a new issue, or post my schema here?

This should be fixed by https://github.com/prisma/prisma-engine/pull/82

The problem was that we weren’t separating between models when validating that relation fields weren’t causing any ambiguity, so there were false positives. The fix will be in the next preview 😃

The PR also contains another change that makes the check for ambiguity in self relationships (model fields that refer to the same model) stricter.

Before, with this model:

model Human {
    id Int @id
    parent Human
    child Human
}

we would have inferred a single self-relation with parent and child as the two ends.

Now this model is invalid, you need to specify whether you want two self relations or one, by using @relation("NameOfTheRelation").

More info on this change in this schema spec PR: https://github.com/prisma/specs/pull/201

@imVinayPandya We will work on this in this sprint 👍