#Second time migration error with enum
7 messages · Page 1 of 1 (latest)
When you encounter an error during a second migration involving enums (for example, adding a new enum value or a new field of enum type), this is a known issue with Prisma Migrate, especially on PostgreSQL. Common causes include:
-
Adding/Removing Enum Values and Fields Simultaneously: If you try to add a new enum field to a model and remove an enum value in the same migration, Prisma may generate SQL that tries to alter a column before it exists, resulting in a migration failure. The generated SQL might attempt to change the type of a column that hasn't been created yet, causing errors like "current transaction is aborted" or similar. The workaround is to split your changes into separate migrations: first update the enum, then add the new field in a subsequent migration. This issue is confirmed and tracked by the Prisma team Adding an enum field and removing an enum value generates a failing migration.
-
PostgreSQL Transaction Limitations: When adding a new value to an enum and immediately using it as a default or in data, PostgreSQL requires the enum change to be committed before the new value can be used. This means you must split the migration into two steps: one to add the enum value, and another to use it (e.g., as a default). Attempting both in a single migration will fail with errors like "New enum values must be committed before they can be used" Migration doesn't work when adding new value to enum and using new value as default.
How to resolve:
- Make enum changes (add/remove values) in one migration, apply it.
- In a separate migration, add new fields or use the new enum values.
If you provide the exact error message, I can give more targeted advice, but these are the most common enum-related migration issues in Prisma.
When first time I run migrate with Role and user it's work.
But when I add age column it's give us error.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
So the error was resolved when you removed multiSchema preview feature?