Skip to content

Mutliple 1-n self relations break migrations #3805

@DOSBNM-billing

Description

@DOSBNM-billing

Bug description

I cannot successfully run prisma migrate up --experimantal when using multiple 1-n self relations with following error:

Error: Failure during a migration command: Connector error. (error: Error querying the database: Error querying the database: db error: ERROR: column "userId" specified more than once
   0: migration_core::api::ApplyMigration
           with migration_id="20200926060127-a"
             at migration-engine/core/src/api.rs:87)

How to reproduce

Based on the example provided in Prisma self-relation docs I have following schema which results in above error when running as single migration:

model User {
  id          Int      @id @default(autoincrement())
  name        String?
  husband     User?    @relation("MarriagePartners")
  wife        User     @relation("MarriagePartners")
  teacher     User?    @relation("TeacherStudents")
  students    User[]   @relation("TeacherStudents")
}

However, when I run migrations as consecutive migrations it works:

  1. migrate this initial schema:
model User {
  id          Int      @id @default(autoincrement())
  name        String?
  husband     User?    @relation("MarriagePartners")
  wife        User     @relation("MarriagePartners")
}
  1. then migrate this updated schema:
model User {
  id          Int      @id @default(autoincrement())
  name        String?
  husband     User?    @relation("MarriagePartners")
  wife        User     @relation("MarriagePartners")
  teacher     User?    @relation("TeacherStudents")
  students    User[]   @relation("TeacherStudents")
}

Expected behavior

Pass migration with single migration of complete schema!

Environment & setup

  • OS: debian
  • Database: PostgreSQL
  • Node.js version: v14.0.0
  • Prisma version: @prisma/cli : 2.7.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions