Adding indexes to SQLAlchemy models after table creation

前端 未结 6 1110
野性不改
野性不改 2021-01-31 16:20

I have a flask-sqlalchemy model:

class MyModel(db.Model):
__tablename__ = \'targets\'
id = db.Column(db.Integer, primary_key=True)
url = db.Column(db.String(2048         


        
6条回答
  •  梦如初夏
    2021-01-31 16:57

    Since the question was asked, support has been added for this.

    Now you can just add index=True to an existing column, and auto-generate the migration.

    Checked on the following package versions:

    alembic==1.0.10
    SQLAlchemy==1.3.4
    SQLAlchemy-Utils==0.34.0
    Flask-SQLAlchemy==2.4.0
    Flask-Migrate==2.5.2
    

提交回复
热议问题