I’m running into an issue with Prisma + SQL Server when using a custom schema (not dbo)

Here’s what I’m doing: • I’m using a custom schema called custom_schema and mapped my models with @@map or @map("custom_schema.TableName"). • I manually created the schema custom_schema in the database before running the initial migration. • Running the initial migration with prisma migrate dev on a clean database worked fine. It created the custom_schema tables and the _prisma_migrations table, and the migration completed successfully. • Later, when I tried to create a second migration using pnpm prisma migrate dev --name test_migration, I ran into this error:
Error: P3006
Migration 20250423052852_init failed to apply cleanly to the shadow database.
Error:
The specified schema name "custom_schema" either does not exist or you do not have permission to use it.
0: sql_schema_connector::validate_migrations
with namespaces=None
at schema-engine/connectors/sql-schema-connector/src/lib.rs:362
1: schema_core::state::DevDiagnostic
at schema-engine/core/src/state.rs:276
Error: P3006
Migration 20250423052852_init failed to apply cleanly to the shadow database.
Error:
The specified schema name "custom_schema" either does not exist or you do not have permission to use it.
0: sql_schema_connector::validate_migrations
with namespaces=None
at schema-engine/connectors/sql-schema-connector/src/lib.rs:362
1: schema_core::state::DevDiagnostic
at schema-engine/core/src/state.rs:276
I understand that Prisma drops and recreates the shadow database during migrate dev, and since Prisma doesn’t auto-create custom schemas in SQL Server, the custom_schema schema doesn’t exist when it tries to apply the migration to the shadow DB—hence the error. I also tried specifying a shadowDatabaseUrl manually and pre-creating the schema there, but since the shadow DB gets wiped and recreated by Prisma anyway, that didn’t help either. Is there an official or recommended way to use custom schemas with SQL Server in Prisma and still be able to use migrate dev reliably? Thanks in advance for any insights 🙏
4 Replies
Prisma AI Help
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
hyteq
hyteq3w ago
drizzle switched once never turned back bit more complex setup but worth it
Nurul
Nurul3w ago
Hey @Christopher I believe your issue is similar to what is described in this issue: https://github.com/prisma/prisma/issues/17574 Can you check?
GitHub
MSSQL migration failed to apply to the shadow database after creati...
Bug description We are using MSSQL for our database and are currently facing an issue with the shadow db when trying the migrate. When running prisma migrate dev a second time after creating the in...
Christopher
ChristopherOP3w ago
there is no support for MSSQL Yes thats the exact problem i am facing but i didn't manage to find a solution described in the github issue

Did you find this page helpful?