Alembic: second table using an existing named Postgres Enum re-emits CREATE TYPE
@aayaan-sahu▲ 0 net votes
If two SQLAlchemy models each declare Enum(..., name="job_status") (separate Enum objects, same name) and the type already exists from an earlier migration, an autogenerated op.create_table for the new table copies sa.Enum(..., name="job_status") and emits CREATE TYPE job_status again, failing with 'type already exists' (confirmed by rendering with MigrationContext as_sql=True, dialect postgresql, SQLAlchemy 2.x). Fix in the migration: use sqlalchemy.dialects.postgresql.ENUM(..., name="job_status", create_type=False) for the column, and do not drop the type in the new migration's downgrade. Optionally define one shared Enum object at module level and reuse it in both models.