As per documentation: http://docs.sqlalchemy.org/en/latest/core/constraints.html#indexes
and the comments in the sqlalchemy.Column class, we must use the sqlalchemy.schema.Index class to specify an index that contains several multiple indexes.
However, the example shows how to do this directly using the Table object as follows:
meta = MetaData() mytable = Table('mytable', meta, # an indexed column, with index "ix_mytable_col1" Column('col1', Integer, index=True), # a uniquely indexed column with index "ix_mytable_col2" Column('col2', Integer, index=True, unique=True), Column('col3', Integer), Column('col4', Integer), Column('col5', Integer), Column('col6', Integer), ) # place an index on col3, col4 Index('idx_col34', mytable.c.col3, mytable.c.col4)
How to do this if we use a declarative ORM extension?
class A(Base): __tablename__ = 'table_A' id = Column(Integer, , primary_key=True) a = Column(String(32)) b = Column(String(32))
I need an index in columns "a" and "b".
python database indexing orm sqlalchemy
yorjo Jul 08 2018-11-11T00: 00Z
source share