Unclear error message when using prisma-level default functions (cuid, uuid) as default for non-nullable fields
See original GitHub issueBug 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
- Create a migration with a model and some columns.
- Add a NON NULLABLE column to that model.
- Save the changes and run the migration.
- 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
prisma nullable column | The Search Engine You Control
prisma/prismaUnclear error message when using prisma-level default functions (cuid, uuid) as default for non-nullable fields#4691. Created over 2 years ago.
Read more >Prisma 2.19.0 Release - GitClear
Better error when adding a new required field and the default value is Prisma-level, e.g. uuid(); Small improvement where Prisma Migrate failed ...
Read more >MySQL 8.0.13: Default Value as uuid not working
This is unfortunately a bug with default expressions for primary key columns, Expression Default is made NULL during CREATE TABLE query, ...
Read more >Default value for UUID column in Postgres
tl;dr. Call DEFAULT when defining a column to invoke one of the OSSP uuid functions. The Postgres server will automatically invoke the ...
Read more >@prisma/cli: Versions | Openbase
... when using prisma migrate dev · Unclear error message when using prisma-level default functions (cuid, uuid) as default for non-nullable fields ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
cuid()
anduuid()
are not database-level defaults — they are instead populated by the prisma-client. The only workaround in this case is to add the columns as optional, populate them, then make them required. I’ll keep this issue open as a reminder to expand the error message.Hi! I had a same problem, having error <Step 1 Added the required column
password
to theUser
table without a default value. There are 1 rows in this table, it is not possible to execute this migration.> So I checked my MySQL Workbench and I found that there is a data. So I erased it… and it finally worked! Here is my code