I'm defining a table in SQLAlchemy using the declarative API. It's got a foreign key which I'd like to index. My question is: how do I define the index created from master_ref to be an ASC or DESC index (without resorting to doing it manually with SQL)?
class Item(Base):
id = Column(INTEGER, primary_key=True)
master_ref = Column(INTEGER, ForeignKey('master.id'), nullable=True, index=True)
value = Column(REAL)
Looking at the documentation of SqlAlchemy, an alternative way to create the index would be:
class Item(Base):
id = Column(INTEGER, primary_key=True)
master_ref = Column(INTEGER, ForeignKey('master.id'))
value = Column(REAL)
Index('ix_name', master_ref)
but I cannot find any reference on how to define the ASC or DESC anywhere.
Indexin__table_args__if defining it in the class body, though your example would also work due to using the actualColumnobject in defining the index.