'SQLAlchemy, InstrumentedAttribute, Column, Attribute

Suppose I have a Column definition like this in my SQLAlchemy model:

value = Column(String(500, collation="utf8mb4_unicode_ci"), nullable=False)

I need to obtain the value of "collation".

I have an instance of InstrumentedAttribute (for that column) in my method.

How to navigate to that information?



Solution 1:[1]

value.type.collation

value = Column(String(500, collation="utf8mb4_unicode_ci"), nullable=False)
print(value.type.collation)
# utf8mb4_unicode_ci

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gord Thompson