Defining SQLAlchemy enum column with Python enum raises “ValueError: not a valid enum”

前端 未结 1 2123
温柔的废话
温柔的废话 2020-12-24 11:42

I am trying to follow this example to have an enum column in a table that uses Python\'s Enum type. I define the enum then pass it to the column as shown in th

1条回答
  •  攒了一身酷
    2020-12-24 11:54

    The column type should be sqlalchemy.types.Enum. You're using the Python Enum type again, which is valid for the value but not the column type.

    class MyTable(db.Model):
        id = db.Column(db.Integer, primary_key = True)
        fruit_type = db.Column(db.Enum(FruitType))
    

    0 讨论(0)
提交回复
热议问题