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.

A migration of @default(cuid()) inserts null values to the DB #574

@AviBueno

Description

@AviBueno

Bug description

Adding a new column with @default(cuid()) ends up with null values in the new column after migration.

How to reproduce

Add a new column to an existing table, e.g.:

model Folder {
  ...
  uid String? @default(cuid())
  ...
}

Run prisma migrate save --experimental followed by prisma migrate up --experimental

Notes:

  1. Tried with and without @unique and the result is the same
  2. String? type is required as String crashes the migration. Not sure why. It would be preferred that the column would be mandatory.

Edit:

With String as the type, the migration fails on the following error, which is also described in #527:

Added the required column X to the Y table without a default value. There are N rows in this table, it is not possible to execute this migration.

Expected behavior

The Folder table should contain a new uid column with generated cuid values.

Prisma information

N/A

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v12.18.3
  • Prisma version:
@prisma/cli          : 2.5.1
Current platform     : darwin
Query Engine         : query-engine c88925ce44a9b89b4351aec85ba6a28979d2658e (at node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli c88925ce44a9b89b4351aec85ba6a28979d2658e (at node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core c88925ce44a9b89b4351aec85ba6a28979d2658e (at node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary        : prisma-fmt c88925ce44a9b89b4351aec85ba6a28979d2658e (at node_modules/@prisma/cli/prisma-fmt-darwin)
Studio               : 0.261.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions