Skip to content

Instantly share code, notes, and snippets.

@moraisaugusto
Created June 17, 2020 14:57
Show Gist options
  • Save moraisaugusto/fb2f5d2203a8d2faeece3b0e594c6499 to your computer and use it in GitHub Desktop.
Save moraisaugusto/fb2f5d2203a8d2faeece3b0e594c6499 to your computer and use it in GitHub Desktop.
SQLAlchemy - Add Enumeration record

SQLAlchemy doesn't generate a CREATE/DROP script for an existing enumeration datatype in Postgresql. For that, you need to manually change your generated version script - versions/HASH_NUMBER.py and change the datatype manually.

versions/SHA.py

def upgrade():
    if not op.get_context().as_sql:
        connection = op.get_bind()
        connection.execution_options(isolation_level='AUTOCOMMIT')

    op.execute("ALTER TYPE currency ADD VALUE IF NOT EXISTS 'BRL'")

or you can do it directly on the psql client.

issue related: sqlalchemy/alembic#123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment