我的桌子有一种
contact_type
:
List of data types
Schema | Name | Internal name | Size | Elements | Owner | Access privileges | Description
--------+---------------+---------------+------+---------------+----------+-------------------+-------------
public | contact_types | contact_types | 4 | unknown +| postgres | |
| | | | incoming_text+| | |
| | | | incoming_call+| | |
| | | | outgoing_call | | |
在表格中:
Table "public.calls"
Column | Type | Modifiers
--------------+--------------------------+----------------------------------------------------
contact_type | contact_types |
在python中,我创建了
enum
每
the docs
:
import enum
class contact_types(enum.Enum):
unknown: 1
incoming_text: 2
incoming_call: 3
outgoing_call: 4
class Call(db.Model):
contact_type = db.Column(db.Enum(contact_types))
一切看起来都很好。插入工作,我可以在查看表时看到值,但是SQLAlchemy的验证在查询时似乎不满意。这会导致错误:
calls = Call.query.order_by(Call.time.desc()).limit(pagesize).offset(offset)
for c in calls:
print(c)
“未知”在枚举中。我是否缺少将查询连接到枚举类的步骤?