我在mysql中有这个表
import peewee
class User(peewee.Model):
username = peewee.Charfield(max_length=60)
email = peewee.Charfield(max_length=300)
def __repr__(self):
return "<User: {}>".format(self.username)
当我为现有用户尝试以下代码时:
User.get(email="zhaochang@qq.com")
它返回<User: zhaochang>
但对于不存在的随机电子邮件/用户User.get(email="some_random@email.com")
,它会抛出错误:
UserDoesNotExist:Instance matching query does not exist:
SQL: SELECT 't1'.'id', 't1'.'email', 't1'.'username' FROM 'user' AS t1 WHERE ('t1'.'email' = %s)
PARAMS: [u'some_random@email.com']
我在期待用户.get方法返回None。你知道吗
当文档清楚地表明
资料来源:http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get
相关问题 更多 >
编程相关推荐