我在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")
它会引发错误:
用户不存在: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']
我期待 User.get 方法返回无。