How to create ENUM in SQLAlchemy?

后端 未结 1 1825
南笙
南笙 2021-02-20 04:04
from sqlalchemy import *
from migrate import *

meta = MetaData()
race_enums = (\'asian\',\'mideastern\',\'black\',\'nativeamerican\',\'indian\',\'pacific\',\'hispanic\'         


        
相关标签:
1条回答
  • 2021-02-20 04:25

    You need pass race_enum as an argument for Enum, not Column

    You can either pass in your tuple as whole

    Column('race', Enum('asian','mideastern','black','nativeamerican','indian','pacific','hispanic','white','other'))
    

    or use * to unpack race_enums:

    Column('race', Enum(*race_enums))
    
    0 讨论(0)
提交回复
热议问题