Autogenerate with Enums on postgres don't preserve Enum name, doesn't drop enum definition on downgrade

Issue #67 resolved
Anonymous created an issue

Two issues, first, my definition is something like:

Enum(..., name="my_enum")

but it ends up in the migration as Enum(...), no name:

sqlalchemy.exc.CompileError: Postgresql ENUM type requires a name.


Second thing, the first time I run the migration everything works as expected, but downgrading doesn't drop the created enum, which makes upgrading again fail:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) type "my_enum" already exists "CREATE TYPE my_enum AS ENUM (...)" {}

Comments (3)

  1. Michael Bayer repo owner

    for the second issue, you need to use `create()` and `drop()` on the ENUM directly so that when the type is created and dropped can be controlled. this is from the tests:

    from alembic import op
    from sqlalchemy.dialects.postgresql import ENUM
    from sqlalchemy import Column
    def upgrade():
        enum = ENUM("one", "two", "three", name="pgenum", create_type=False)
        enum.create(op.get_bind(), checkfirst=False)
            Column("data", enum)
    def downgrade():
        ENUM(name="pgenum").drop(op.get_bind(), checkfirst=False)
  2. Log in to comment