Skip to content

Postgresql get_indexes() is erroneously returning EXCLUDE constraints, look to duplicates_index flag as an indicator to skip #461

@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Fredrik Blomqvist (@fgblomqvist)

When autogenerating migrations alembic wants to drop the excludeconstraint from my DB.

INFO  [alembic.autogenerate.compare] Detected removed index 'quarters_period_excl' on 'quarters'

The database in use is PostgreSQL 9.6.5.
The ExcludeConstraint is defined in the table_args at the end of the model, and it is created when doing SQLAlchemy create_all.

The import:

from sqlalchemy.dialects.postgresql import ExcludeConstraint

The table args:

__table_args__ = ( 
    ExcludeConstraint(('period', '&&'), name='quarters_period_excl'), 
    db.UniqueConstraint('year', 'name', 'university_id'), 
    db.CheckConstraint(name.in_(['Fall', 'Winter', 'Spring', 'Summer'])) )

This is the code alembic generates:

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('quarters_period_excl', table_name='quarters')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_index('quarters_period_excl', 'quarters', ['period'], unique=False)
    # ### end Alembic commands ###

If this does not ring a bell, I can try to put together an MCV example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions