-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Bug description
When working with multiple database schemas in Prisma, I encountered the following problem:
- Initial setup: Created a
User
table in thedbo
schema through my first migration - Second migration: Added an identical
User
table in thenew
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
Reproduction
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