[Fixed]-Django CharField blank vs default empty

24๐Ÿ‘

โœ…

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.

๐Ÿ‘คfalsetru

Leave a comment