weixin_39890652 2020-11-30 11:37
浏览 0

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

Migrated issue, originally created by Fredrik Blomqvist ()

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.

该提问来源于开源项目:sqlalchemy/alembic

  • 写回答

13条回答 默认 最新

  • weixin_39890652 2020-11-30 11:37
    关注

    Michael Bayer () wrote:

    this is an enhancement as there are many things autogenerate does not detect (See the last paragraph where constraint types such as EXCLUDE are mentioned).

    评论

报告相同问题?