question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma 4.6.0 drops and recreates enum field when running db push even if the field has not changed

See original GitHub issue

Bug description

I just updated from Prisma 4.5.0 to 4.6.0 and now every time I run npx prisma db push, even if I haven’t changed anything in schema.prisma, Prisma wants to drop and recreate an enum field. I get this message:

The `roles` column on the `User` table would be dropped and recreated. This will lead to data loss

If I choose to ignore the warning all my data in the roles column is reset.

After testing with multiple changes to my schema and simplifying it to the most basic form (included below) I downgraded to Prisma 4.5.0 and everything works as expected there. I’ve reconfirmed the problem exists by going back to Prisma 4.6.0.

How to reproduce

  1. Use the provided basic schema.prisma. Pay attention to the roles field, which is an enum.
  2. Create at least one row in the user table containing a value for the roles field.
  3. Run npx prisma db push multiple times without changing anything in schema.prisma.
  4. You will see The rolescolumn on theUser table would be dropped and recreated. This will lead to data loss, and if you accept the warning the data in the roles column will be reset.

Expected behavior

The roles enum column is not being changed in schema.prisma so it shouldn’t be dropped and recreated when running npx prisma db push.

Prisma information

model User {
  id                    Int               @id @default(autoincrement())
  username              String            @unique @db.VarChar(32)
  roles                 Role[]            @default([COLLECTOR])
}

enum Role {
  ADMIN
  COLLECTOR
}
// Add your code using Prisma Client

Environment & setup

  • OS: Ubuntu Linux
  • Database: PostgreSQL 14.2
  • Node.js version: 18.0.0

Prisma Version

4.6.0

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:19
  • Comments:33 (18 by maintainers)

github_iconTop GitHub Comments

5reactions
jansedloncommented, Nov 10, 2022

@Jolg42 4.6.1-dev.1 fixed it for me

4reactions
Jolg42commented, Nov 9, 2022

@alexisbellido @rcbevans @bsproul @hoghweed @davidlumley Could you try to update prisma and @prisma/client to the 4.6.1-dev.1 internal patch version that includes the fixes and let us know if that solves your issue?

We will wait for some confirmations before we publish the official patch to latest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma 4.6.1 Release - GitClear
prisma /prisma ... 4.6.0 (released November 8, 2022) ... and recreates enum field when running db push even if the field has not...
Read more >
Updating Enum Values in PostgreSQL - The Safe and Easy Way
"Drop and re-create the type." This solution alone is no good if the type is already in use as you would have to...
Read more >
@prisma/engines: Versions | Openbase
Fix in Prisma Migrate. Prisma 4.6.0 drops and recreates enum field when running db push even if the field has not changed ......
Read more >
how change the column of a table of enum type? - Laracasts
run as raw query is not good practice ... because it may not work on all database engine that laravel works with. solution...
Read more >
Prisma Versions - Open Source Agenda
If your application encounters an error as the transaction is being ... Prisma 4.6.0 drops and recreates enum field when running db push...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found