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.
精彩评论