Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying enum value in Postgres causes an error #7712

Closed
jacktan165 opened this issue Jun 17, 2021 · 7 comments · Fixed by prisma/prisma-engines#2121
Closed

Modifying enum value in Postgres causes an error #7712

jacktan165 opened this issue Jun 17, 2021 · 7 comments · Fixed by prisma/prisma-engines#2121
Assignees
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: enum "type"/block `enum` topic: error
Milestone

Comments

@jacktan165
Copy link

jacktan165 commented Jun 17, 2021

Bug description

⚠️  Warnings:

  • The values [LOW_FOODMAP] on the enum `Diet` will be removed. If these variants are still used in the database, this will fail.

✔ Are you sure you want create and apply this migration? Some data will be lost. … yes
✔ Name of migration … remove_low_foodmap
Error: Database error
Error querying the database: db error: ERROR: current transaction is aborted, commands ignored until end of transaction block
   0: migration_core::api::ApplyMigrations
             at migration-engine/core/src/api.rs:73

I removed LOW_FOODMAP and that error occurs.

When you try to run a SQL query that involves that enum you get this error

  PANIC in /root/.cargo/git/checkouts/rust-postgres-dc0fca9be721a90f/8a61d46/postgres-types/src/lib.rs:762:18
expected array type

If I run prisma db push I get this:

Error: Database error
Error querying the database: db error: ERROR: invalid input value for enum "Diet_new": "{}"
   0: sql_migration_connector::sql_database_step_applier::apply_migration
             at migration-engine/connectors/sql-migration-connector/src/sql_database_step_applier.rs:14
   1: migration_core::api::SchemaPush
             at migration-engine/core/src/api.rs:165

How to reproduce

  1. Create the schema with an enum and migrate for the first time, so far everything works.
  2. Modify the enum (if you add a new value it is fine, this error occurs only when you removed a value).
  3. Run prisma migrate dev
  4. See error.

Expected behavior

No response

Prisma information

This is the schema:

enum Allergy {
  GLUTEN
  PEANUT
  SEAFOOD
  SESAME
  SOY
  DAIRY
  EGG
  WHEAT
  LOW_FOODMAP
}

to

enum Allergy {
  GLUTEN
  PEANUT
  SEAFOOD
  SESAME
  SOY
  DAIRY
  EGG
  WHEAT
}

migration.sql

/*
  Warnings:

  - The values [LOW_FOODMAP] on the enum `Diet` will be removed. If these variants are still used in the database, this will fail.

*/
-- AlterEnum
BEGIN;
CREATE TYPE "Diet_new" AS ENUM ('KETOGENIC', 'VEGETARIAN_NO_MEAT_AND_EGGS', 'VEGETARIAN_NO_MEAT_AND_DAIRY', 'PESCATARIAN', 'VEGAN', 'VEGETARIAN', 'PALEO');
ALTER TABLE "Recipe" ALTER COLUMN "diets" TYPE "Diet_new" USING ("diets"::text::"Diet_new");
ALTER TABLE "User" ALTER COLUMN "diets" TYPE "Diet_new" USING ("diets"::text::"Diet_new");
ALTER TYPE "Diet" RENAME TO "Diet_old";
ALTER TYPE "Diet_new" RENAME TO "Diet";
DROP TYPE "Diet_old";
COMMIT;

Prisma Version

2.25.0
@jacktan165 jacktan165 added the kind/bug A reported bug. label Jun 17, 2021
@jacktan165 jacktan165 changed the title Modifying enum value causes an error Modifying enum value in Postgres causes an error Jun 17, 2021
@tomhoule tomhoule added process/candidate team/schema Issue for team Schema. labels Jun 17, 2021
@tomhoule
Copy link
Contributor

Thanks for the issue. The error messages aren't clear, we should start by looking into that (there are plans to improve this).

@melissafzhang
Copy link

I'm also seeing this error when I try to convert a String into an enum

@tomhoule
Copy link
Contributor

tomhoule commented Jul 1, 2021

Hi @melissafzhang , thanks for reporting that — could you please open a separate issue? It should be treated as a separate bug.

@tomhoule
Copy link
Contributor

tomhoule commented Jul 1, 2021

@jacktan165 we released improvements to error messages on postgres in 2.26.0 — can you see if it addresses the bad error message problem for you? Issue: #7908

@pantharshit00
Copy link
Contributor

ping @jacktan165

@bogordesaincom
Copy link

i have same problem. any solution?

@janpio
Copy link
Member

janpio commented Jan 29, 2022

Open a new issue and describe your problem with all information the issue template asks for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: enum "type"/block `enum` topic: error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants