Reputation: 3677
What is the difference between this two fields in a Django app? What behaviour should I expect?
field_a = CharField(max_length=50, verbose_name='field_a', blank=True)
field_b = CharField(max_length=50, verbose_name='field_b', blank=True, default='')
Upvotes: 15
Views: 10379
Reputation: 368974
If default
value is not given, empty string is used for CharField
according to the following code (taken from django/db/models/fields/__init__.py
source):
def get_default(self):
"""
Returns the default value for this field.
"""
if self.has_default():
if callable(self.default):
return self.default()
return self.default
if (not self.empty_strings_allowed or (self.null and
not connection.features.interprets_empty_strings_as_nulls)):
return None
return ""
So they should behave same.
Upvotes: 24