Python – Alembic removes indexes for foreign keys

Alembic removes indexes for foreign keys… here is a solution to the problem.

Alembic removes indexes for foreign keys

I have a column address_id = db. Column(db. Integer, db. ForeignKey(Address.id, ondelete='CASCADE'), index=True)。 Auto-generating migrations with Alembic always adds an drop_index action.

op.drop_index('address_id', 'companies')

Why does this happen every time I build a migration?

Solution

This is a known bug in still 0.6.1. Upgrade to 0.6.2 or later and the issue will disappear.

Related Problems and Solutions