P
Prisma2w ago
Uncle

Changing Enum types

Hello I have an Enum that I need to change. The enum was
enum PaymentType {
STRIPE
CASH
CHECK
}
enum PaymentType {
STRIPE
CASH
CHECK
}
and I need it to be
enum PaymentType {
CREDIT
CASH
CHECK
}
enum PaymentType {
CREDIT
CASH
CHECK
}
When I do pnpm prisma db push I get an error:
Error: ERROR: invalid input value for enum "PaymentType_new": "STRIPE"
0: sql_schema_connector::apply_migration::migration_step
with step=AlterEnum(AlterEnum { id: MigrationPair { previous: EnumId(0), next: EnumId(0) }, created_variants: ["CREDIT"], dropped_variants: ["STRIPE"], previous_usages_as_default: [] })
at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:28
1: sql_schema_connector::apply_migration::apply_migration
at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:11
2: schema_core::state::SchemaPush
at schema-engine/core/src/state.rs:502
Error: ERROR: invalid input value for enum "PaymentType_new": "STRIPE"
0: sql_schema_connector::apply_migration::migration_step
with step=AlterEnum(AlterEnum { id: MigrationPair { previous: EnumId(0), next: EnumId(0) }, created_variants: ["CREDIT"], dropped_variants: ["STRIPE"], previous_usages_as_default: [] })
at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:28
1: sql_schema_connector::apply_migration::apply_migration
at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:11
2: schema_core::state::SchemaPush
at schema-engine/core/src/state.rs:502
I also can't seed the database. How do I reset the database so I can change the Enum?
1 Reply
Prisma AI Help
You chose to compile with the bot. One moment while I piece together your answer… This error occurs because you are removing the STRIPE value from the PaymentType enum, but there is still data in your database using that value. When Prisma tries to migrate, it cannot convert existing rows with STRIPE to the new enum, resulting in the error you see. How to reset the database so you can change the Enum: 1. Delete or update rows using the old enum value:
Before running the migration, you need to remove or update all rows in your database that use the STRIPE value. You can do this manually with SQL, for example:
DELETE FROM "YourTable" WHERE "paymentType" = 'STRIPE';

DELETE FROM "YourTable" WHERE "paymentType" = 'STRIPE';

Or, if you want to update them to the new value:
UPDATE "YourTable" SET "paymentType" = 'CASH' WHERE "paymentType" = 'STRIPE';

UPDATE "YourTable" SET "paymentType" = 'CASH' WHERE "paymentType" = 'STRIPE';

Replace "YourTable" and "paymentType" with your actual table and column names. 2. Reset the database (development only):
If you are in development and can afford to lose all data, you can use:
pnpm prisma migrate reset

pnpm prisma migrate reset

This will drop the database, reapply all migrations, and re-seed it. This is the easiest way to resolve enum change issues in development environments, as confirmed in several issues (see example). 3. Rerun your migration:
After cleaning up the data or resetting the database, run:
pnpm prisma db push

pnpm prisma db push

or
pnpm prisma migrate dev

pnpm prisma migrate dev

Note:
If you are in production, you must carefully migrate your data before removing enum values to avoid data loss and migration failures. Prisma currently does not handle renaming or removing enum values gracefully if existing data uses them (see related issues, <https://github.com/prisma/prisma/issues/7712). If you continue to have issues, ensure there are no default values or constraints referencing the old enum value before migra tion (see also). ✅ Great, thanks for letting us know that this solved your question!

Did you find this page helpful?