1. Andrew Godwin
  2. south


Andrew Godwin  committed 06124b8

Fixing default behaviour on columns with null=False

  • Participants
  • Parent commits f79398a
  • Branches default

Comments (0)

Files changed (2)

File south/db/generic.py

View file
                         default = "'%s'" % default
                     sql += " DEFAULT %s"
                     sqlparams = (default)
-            elif not field.null and field.blank:
+            elif (not field.null and field.blank) or field.get_default() == '':
                 if field.empty_strings_allowed:
                     sql += " DEFAULT ''"
                 # Error here would be nice, but doesn't seem to play fair.

File south/db/sqlite3.py

View file
         # Run ALTER TABLE with no unique column
         unique, field._unique, field.db_index = field.unique, False, False
         # If it's not nullable, and has no default, raise an error (SQLite is picky)
-        if not field.null and (not field.has_default() or field.get_default() is None):
+        if (not field.null and 
+            (not field.has_default() or field.get_default() is None) and
+            not field.empty_strings_allowed):
             raise ValueError("You cannot add a null=False column without a default value.")
         # Don't try and drop the default, it'll fail
         kwds['keep_default'] = True