`ALTER TYPE` enum migrations fail in PostgreSQL
See original GitHub issueBug description
Using migrations from version 2.14
, I updated an enum to add a few more values.
That generated the following migration.
-- AlterEnum
ALTER TYPE "account_type_enum" ADD VALUE 'Giving';
ALTER TYPE "account_type_enum" ADD VALUE 'Parent';
ALTER TYPE "account_type_enum" ADD VALUE 'Saving';
ALTER TYPE "account_type_enum" ADD VALUE 'Spending';
-- AlterTable
ALTER TABLE "account" ALTER COLUMN "type" SET DEFAULT E'Spending';
Unfortunately, when running this, I get the following error from Postgres.
Database error: Error querying the database: db error: ERROR: ALTER TYPE ... ADD cannot run inside a transaction block
0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:174
1: sql_migration_connector::sql_database_migration_inferrer::validate_migrations
at migration-engine/connectors/sql-migration-connector/src/sql_database_migration_inferrer.rs:89
2: migration_core::api::DiagnoseMigrationHistory
at migration-engine/core/src/api.rs:109
I can confirm that reducing the migration to a single ALTER TYPE
solves the issue.
How to reproduce
- Use Postgres
- Create an enum
- Add multiple new values
- Generate a migration
- Run the migration
Expected behavior
New enum values should be added.
Environment & setup
- OS: Mac OS
- Database: PostgreSQL 11
- Node.js version: 4.15
- Prisma version:
@prisma/cli : 2.14.0
@prisma/client : 2.14.0
Current platform : darwin
Query Engine : query-engine 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 5d491261d382a2a5ffdc71de17072b0e409f1cc1 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio : 0.332.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Documentation: 15: ALTER TYPE - PostgreSQL
This form adds a new value to an enum type. The new value's place in the enum's ordering can be specified as being...
Read more >Altering Enum type in Postgres gets 42883 error
1 Answer 1 · Using Postgres 12.3 and the error comes up using a migration through an Elixir app and through the application...
Read more >[Solved]-Migration error: ENUM type already exists-postgresql
Since you already have a status enum type from your previous model, the solution is extremely easy and straightforward: just specify the type...
Read more >Dealing with Enum Type in PostgreSQL - DEV Community
How are you handling migrations where some of the enum values are removed? Existing data are using an enum value which should be...
Read more >Upgrading PostgreSQL's Enum type with ... - Makimo
Furthermore if you are using an older version of PostgreSQL (<12) you will have to add an autocommit block every time when using...
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
It seems that this restriction is not valid anymore for PostgreSQL versions higher than 11. On versions 12 and 13 I can successfully execute this migration.
Created https://github.com/prisma/prisma/issues/5543 for us to add a comment with a warning, suggesting users of PostgreSQL 11 and earlier versions to only add one ENUM value at a time in each migration.