Andrew Godwin avatar Andrew Godwin committed 06124b8

Fixing default behaviour on columns with null=False

Comments (0)

Files changed (2)

south/db/generic.py

                         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.

south/db/sqlite3.py

         # 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
 
         generic.DatabaseOperations.execute_deferred_sql(self)
 
-    
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.