开发者

StringProperty, None vs. Empty String

class Person(d开发者_如何学运维b.Model):
  first_name=db.StringProperty()
  middle_name=db.StringProperty()
  last_name=db.StringProperty()

p1=Person(first_name='john',                 last_name='smith')
p2=Person(first_name='john',middle_name=None,last_name='smith')
p3=Person(first_name='john',middle_name='',  last_name='smith')

p1 and p2 is the same with middle_name = None

p3 has middle_name = empty string

Which is better to work with?

In SQL, I tend to set columns to not null default ''


They're completely different. One (None) is equivalent to SQL NULL. This can mean they don't have a middle name or you don't know it. '' means they do have a middle name, of length 0. This is almost never the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜