Skip to content

Unclear error message when using prisma-level default functions (cuid, uuid) as default for non-nullable fields #4691

@gmencz

Description

@gmencz

Bug description

After adding a NON NULLABLE column with a default value to an existing table with records in the database, I get the following error:

Added the required column `x` to the `y` table without a default value. There are `z` rows in this table, it is not possible to execute this migration.

The model looks like the following:

model MyModel {
    id   String   @default(cuid())             @id
    x    String   @default("Some value")
    // And some other columns...
}

The column causing the error is the x column.

How to reproduce

  1. Create a migration with a model and some columns.
  2. Add a NON NULLABLE column to that model.
  3. Save the changes and run the migration.
  4. See error.

Expected behavior

Migration to be successfully applied.

Environment & setup

  • OS: Windows 10 2004 (Running on WSL 2)
  • Database: PostgreSQL
  • Node.js version: 12.18.2
  • Prisma version: 2.1.3

Metadata

Metadata

Assignees

Labels

kind/featureA request for a new feature.tech/enginesIssue for tech Engines.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions