首页 > Peewee 限制了 Field 中的 choices,为什么仍然可以插入其他数据?

Peewee 限制了 Field 中的 choices,为什么仍然可以插入其他数据?

最近看到 Peewee 这个超简洁的 Python ORM,试着用了下,定义 User 模型:

USER_ROLE = ('user', 'admin')

class User(BaseModel):
    username = CharField()
    role = CharField(choices=USER_ROLE, default='user') 

创建表单后插入数据,注意这个 role 并不在我的 choices 里

k = User(username='admin', role='chairman')
k.save()

发现竟然插入成功了,可是我明明限制了 choices 啊,为什么会这样呢?

【热门文章】
【热门文章】