#25325·Prisma

Migration Failure when Deleting a Column with a Default Value in Microsoft SQL Server

Author: ThomasCode92Created Sep 30, 2024Updated Sep 29, 2026
Labelsbug/1-unconfirmedkind/bugtopic: sql servertopic: prisma migrate dev

Bug description

When attempting to delete a column that has a default value in Microsoft SQL Server, the migration process fails. This issue occurs because SQL Server enforces default constraints on columns, and these constraints must be explicitly dropped before the column can be removed.

How to reproduce

Follow the steps in the Quickstart Guide, but use SQL Server as the database instead of SQLite.

After step 3 of this guide, remove published Boolean @default(false) from the schema and create a migration with npx prisma migrate dev --name remove_published_field.

The migration fails with an error indicating that the column cannot be dropped due to an existing default constraint.

bash
Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 20240930075106_remove_published_field

Database error code: 5074

Database error:
The object 'Post_published_df' is dependent on column 'published'.

Expected behavior

The migration should successfully drop the column along with its default constraint.

Prisma information

prisma
// Add your schema.prisma
typescript
// Add your code using Prisma Client

Environment & setup

  • OS: Ubuntu
  • Database: Microsoft SQL Server
  • Node.js version: 20.11.1

Prisma Version

"prisma": "^5.20.0",