About unique=True and (unique=True, index=True) in sqlalchemy

It is not required. A unique constraint is more often than not implemented using a unique index, but you need not care about that detail, if all you want is uniqueness.


I think you have a term confusion with the index purpose in sqlalchemy. In sql databases index are used speed up query performance.

According to the sqlalchemy documentation of defining constraints and indexes.

You would notice the use of the index key because the sql code generated is:

UNIQUE KEY `ix_tt_t3` (`t3`)

The way how sqlalchemy nouns the index is idx_%columnlabbel. And that matches with the sql code generated.

So the use or not of index it is only related with performance and the unique key means that the column values cannot be repeated all along of the same column in the 'tt' table.

Hope this helps,