Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9862 -- For better SQL portability, don't specify "NULL" on nu…

…llable

columns when creating tables. Patch from Ian Kelly.

Columns are NULL by default, so we only need to use "NOT NULL" when we want
non-default behaviour.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9703 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0c08368116112e43334a05c7e33738d7e75e7bc0 1 parent 391736e
Malcolm Tredinnick authored January 06, 2009

Showing 1 changed file with 3 additions and 3 deletions. Show diff stats Hide diff stats

  1. 6  django/db/backends/creation.py
6  django/db/backends/creation.py
@@ -47,7 +47,8 @@ def sql_create_model(self, model, style, known_models=set()):
47 47
             # Make the definition (e.g. 'foo VARCHAR(30)') for this field.
48 48
             field_output = [style.SQL_FIELD(qn(f.column)),
49 49
                 style.SQL_COLTYPE(col_type)]
50  
-            field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or '')))
  50
+            if not f.null:
  51
+                field_output.append(style.SQL_KEYWORD('NOT NULL'))
51 52
             if f.primary_key:
52 53
                 field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
53 54
             elif f.unique:
@@ -65,8 +66,7 @@ def sql_create_model(self, model, style, known_models=set()):
65 66
             table_output.append(' '.join(field_output))
66 67
         if opts.order_with_respect_to:
67 68
             table_output.append(style.SQL_FIELD(qn('_order')) + ' ' + \
68  
-                style.SQL_COLTYPE(models.IntegerField().db_type()) + ' ' + \
69  
-                style.SQL_KEYWORD('NULL'))
  69
+                style.SQL_COLTYPE(models.IntegerField().db_type()))
70 70
         for field_constraints in opts.unique_together:
71 71
             table_output.append(style.SQL_KEYWORD('UNIQUE') + ' (%s)' % \
72 72
                 ", ".join([style.SQL_FIELD(qn(opts.get_field(f).column)) for f in field_constraints]))

0 notes on commit 0c08368

Please sign in to comment.
Something went wrong with that request. Please try again.