Skip to content

Multischema support for tables with duplicate names not working (Sqlserver) #26899

@YaroBear

Description

@YaroBear

Bug description

When working with multiple database schemas in Prisma, I encountered the following problem:

  1. Initial setup: Created a User table in the dbo schema through my first migration
  2. Second migration: Added an identical User table in the new schema
    • Used proper constraint mapping with unique names to avoid conflicts
    • All database objects had schema-specific unique identifiers

Problem

Despite careful mapping of constraints with unique names across schemas, Prisma reports schema drift when running npx prisma migrate dev after the second migration.

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

Github reproduction code

Expected vs. Actual Behavior

Expected: Prisma should be able to handle duplicate table names so long as they are in different schemas and have unique object names.

Actual: Schema drift detected

Drift detected: Your database schema is not in sync with your migration history.

The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.

It should be understood as the set of changes to get from the expected schema to the actual schema.

[*] Changed the `User` table
  [-] Removed unique index on columns (email)
  [-] Removed index on columns (name)
  [-] Dropped the primary key on columns (id)

We need to reset the following schemas: "dbo, new"

You may use prisma migrate reset to drop the development database.

Frequency

Consistently reproducible

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

I do not believe it is a regression. I have not tested in older version though.

Workaround

The only known workaround is to have unique table names. e.g. have a dbo.User and new.UserV2 tables

Prisma Schema & Queries

Schema 1 (dbo)

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  
  @@map("User")
  @@schema("dbo")
}

Schema 2 (new)

model New_User {
  id    Int     @default(autoincrement())
  email String
  name  String?

  @@id([id], map: "new_User_pkey")
  @@index([name], map: "new_User_name_idx")
  @@unique([email], map: "new_User_email_key")
  @@map("User")
  @@schema("new")
}

Logs & Debug Info

No response

Environment & Setup

  • OS: macOS
  • Database: MS SqlServer
  • Node.js version: v20.17.0

Prisma Version

6.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.topic: multiSchemamultiple schemastopic: sql serverMicrosoft SQL Server

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions