Skip to content
Advertisement

Best way to do enum in Sqlalchemy?

I’m reading about sqlalchemy and I saw following code:

JavaScript

Should I make ‘type’ an int, with constants in a library? Or should I make just make type an enum?

Advertisement

Answer

SQLAlchemy has an Enum type since 0.6: http://docs.sqlalchemy.org/en/latest/core/type_basics.html?highlight=enum#sqlalchemy.types.Enum

Although I would only recommend its usage if your database has a native enum type. Otherwise I would personally just use an int.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement