question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

op.add_column() and op.drop_column() should check for SchemaType, run through the events for that type, or perhaps just create/drop

See original GitHub issue

Migrated issue, originally created by Wichert Akkerman (@wichert)

I have a data model which has a simple enum column:

    size_type = schema.Column(
        types.Enum('normal', 'plus', name='size_type_type'),
        nullable=False, default='normal')

as part of an upgrade routine I need to add that column if it is missing:

    alembic.add_column('article_variant',
            ArticleVariant.__table__.c['size_type'].copy())

alembic is an operation instance here. This operation breaks due to a missing check if the enum type already exists. The resulting error is:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) type "size_type_type" does not exist
LINE 1: ALTER TABLE article_variant ADD COLUMN size_type size_type_t...
                                                         ^
 'ALTER TABLE article_variant ADD COLUMN size_type size_type_type NOT NULL' {}

Issue Analytics

  • State:open
  • Created 11 years ago
  • Reactions:3
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
dwickwirecommented, Jul 28, 2022

Easy workaround:

def downgrade():
    op.execute("""DROP TYPE name_of_enum""")
1reaction
sjlawsoncommented, Jun 23, 2021

Looks like this is still a problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Operation Reference — Alembic 1.9.0 documentation
All directives exist as methods on a class called Operations . When migration scripts are run, this object is made available to the...
Read more >
Dropping foreign keys in Alembic downgrade? - Stack Overflow
However I can't figure out how to drop foreign keys from the Alembic Documentation. Downgrade method: def downgrade(): # Drop Indexes op.
Read more >
How to use the alembic.op.execute function in alembic - Snyk
To help you get started, we've selected a few alembic.op.execute examples, based on popular ways it is used in public projects.
Read more >
ALTER TABLE - Azure Databricks - Microsoft Learn
If you use Unity Catalog you must have MODIFY permission to: ALTER COLUMN; ADD COLUMN; DROP COLUMN; SET TBLPROPERTIES; UNSET TBLPROPERTIES. All ...
Read more >
Alembic Documentation - Read the Docs
env.py - This is a Python script that is run whenever the alembic ... DDLEvents.column_reflect() event to detect when a CHAR (or whatever....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found