Hi I have seen two/three ways to declare index on table:
1. use index=True
class Model(Base):
__tablename__ = "model"
id = sa.Column(sa.Integer, primary_key=True)
field_1 = sa.Column(sa.Integer, index=True)
2. use __table_args__:
class Model(Base):
__tablename__ = "model"
id = sa.Column(sa.Integer)
field_1 = sa.Column(sa.Integer)
__table_args__ = (sa.Index("field_1_index", "field_1"))
3. use Index statement:
class Model(Base):
__tablename__ = "model"
id = sa.Column(sa.Integer)
field_1 = sa.Column(sa.Integer)
Index("field_1_index", "field1")
My question is what's the difference between these 3? Also if I have mixed two of them, what will happen? By this I mean consider the following example;
class Model(Base):
__tablename__ = "model"
id = sa.Column(sa.Integer, primary_key=True)
field_1 = sa.Column(sa.Integer)
__table_args__ = (sa.Index("field_1_index", "field_1"))
Here we are mixing method 1 and 2. From my experiment it seems Postgres can accept this without any problem but Sqlite rejects it outright. Why this happens?
Thanks!
Bob