Skip to content

Cannot migrate changes on Multi Schema setup for SQL Server #24068

@Chibionos

Description

@Chibionos

Bug description

When trying to migrate a Schema that is mapped to the non default schema in SQL Server.
I am getting an error where the migration tries to find the table on the default schema dbo. It is not honoring the custom schema the table is placed in. 

Change I am trying to migrate is make the id property unique and add the NVarChar(450)

Schema

model Report {
  id                  String  @id @unique @db.NVarChar(450)
  title               String
  description         String
  chartType           String? // "line" | "bar" | "pie"
  certificationStatus String // "certified" | "pending" | "uncertified"
  queryMapping        String

  metric        CertifiedMetricVersion @relation(fields: [metricId], references: [Id])
  metricId      Int
  ReportVersion ReportVersion[]

  @@map("Report")
  @@schema("cm")
}
PS D:\r\report-boi> npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": SQL Server database, schemas "cd, cm, gs, sql, ts"

Error: P1014

The underlying table for model `dbo.Report` does not exist.

How to reproduce

Create a schema with a custom schema in SQL Server and try migrating a change.

Expected behavior

Migration should find the right table and generate the migration scripts needed to make the migration possible.

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["multiSchema"]
}

datasource db {
  provider          = "sqlserver"
  url               = env("DATABASE_URL")
  shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
  schemas           = ["cd", "cm", "gs", "sql", "ts"]
}

model Report {
  id                  String  @id @unique @db.NVarChar(450)
  title               String
  description         String
  chartType           String? // "line" | "bar" | "pie"
  certificationStatus String // "certified" | "pending" | "uncertified"
  queryMapping        String

  metric        CertifiedMetricVersion @relation(fields: [metricId], references: [Id])
  metricId      Int
  ReportVersion ReportVersion[]

  @@map("Report")
  @@schema("cm")
}
PS D:\r\report-boi> npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": SQL Server database, schemas "cd, cm, gs, sql, ts"

Error: P1014

The underlying table for model `dbo.Report` does not exist.

Environment & setup

  • OS: Windows
  • Database: SQL Server
  • Node.js version: v18.19.0

Prisma Version

PS D:\r\report-boi> prisma -v
Environment variables loaded from .env
prisma                  : 5.13.0
@prisma/client          : 5.13.0
Computed binaryTarget   : windows
Operating System        : win32
Architecture            : x64
Node.js                 : v18.19.0
Query Engine (Node-API) : libquery-engine b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at C:\ProgramData\nvm\v18.19.0\node_modules\prisma\node_modules\@prisma\engines\query_engine-windows.dll.node)
Schema Engine           : schema-engine-cli b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at C:\ProgramData\nvm\v18.19.0\node_modules\prisma\node_modules\@prisma\engines\schema-engine-windows.exe)
Schema Wasm             : @prisma/prisma-schema-wasm 5.13.0-23.b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
Default Engines Hash    : b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
Studio                  : 0.500.0
Preview Features        : multiSchema

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions