Skip to content
This repository was archived by the owner on Aug 25, 2021. It is now read-only.
This repository was archived by the owner on Aug 25, 2021. It is now read-only.

Removing a model with a foreign key fails #667

@matthewmueller

Description

@matthewmueller

Bug description

Trying to remove a model with a foreign key on a database without data, lands me in a permanently broken state on SQL Server.

Error: Database error: Error querying the database: ''FK__Post__userId__267ABA7A' is not a constraint.' on server 369707b4e132 executing  on line 8 (code: 3728, state: 1, class: 16)
   0: migration_core::api::ApplyMigrations
             at migration-engine/core/src/api.rs:102

How to reproduce

Previous

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

datasource ms {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

model User {
  id   Int     @id @default(autoincrement())
  name String?
  Post Post[]
}

model Post {
  id     Int    @id @default(autoincrement())
  title  String
  User   User   @relation(fields: [userId], references: [id])
  userId Int
}

Current

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

datasource ms {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

model User {
  id   Int     @id @default(autoincrement())
  name String?
  // Post Post[]
}

// model Post {
//   id     Int    @id @default(autoincrement())
//   title  String
//   User   User   @relation(fields: [userId], references: [id])
//   userId Int
// }
npx prisma migrate dev --preview-feature
Environment variables loaded from prisma/.env
Prisma schema loaded from prisma/schema.prisma
Datasource "ms"


✔ Name of migration … 

Error: Database error: Error querying the database: ''FK__Post__userId__267ABA7A' is not a constraint.' on server 417d5b86856f executing  on line 8 (code: 3728, state: 1, class: 16)
   0: migration_core::api::ApplyMigrations
             at migration-engine/core/src/api.rs:102

Puts me in a permanently broken state. I need to manually adjust my SQL scripts to remove the migration.

Expected behavior

This should work as expected.

Environment & setup

  • OS:
  • Database:
  • Node.js version:
  • Prisma version:
Environment variables loaded from prisma/.env
@prisma/cli          : 2.13.0-dev.100
@prisma/client       : 2.13.0-dev.100
Current platform     : darwin
Query Engine         : query-engine 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 833ab05d2a20e822f6736a39a27de4fc8f6b3e49 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.329.0
Preview Features     : microsoftSqlServer

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions