Skip to content
Browse files

[1.0.X] Fixed #9862 -- For better SQL portability, don't specify "NUL…

…L" on nullable 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.

Backport of r9703 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9704 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 7982e5c commit e8ddef57d8379f430456eee4253db612e72a63c2 @malcolmt malcolmt committed
Showing with 3 additions and 3 deletions.
  1. +3 −3 django/db/backends/creation.py
View
6 django/db/backends/creation.py
@@ -47,7 +47,8 @@ def sql_create_model(self, model, style, known_models=set()):
# Make the definition (e.g. 'foo VARCHAR(30)') for this field.
field_output = [style.SQL_FIELD(qn(f.column)),
style.SQL_COLTYPE(col_type)]
- field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or '')))
+ if not f.null:
+ field_output.append(style.SQL_KEYWORD('NOT NULL'))
if f.primary_key:
field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
elif f.unique:
@@ -65,8 +66,7 @@ def sql_create_model(self, model, style, known_models=set()):
table_output.append(' '.join(field_output))
if opts.order_with_respect_to:
table_output.append(style.SQL_FIELD(qn('_order')) + ' ' + \
- style.SQL_COLTYPE(models.IntegerField().db_type()) + ' ' + \
- style.SQL_KEYWORD('NULL'))
+ style.SQL_COLTYPE(models.IntegerField().db_type()))
for field_constraints in opts.unique_together:
table_output.append(style.SQL_KEYWORD('UNIQUE') + ' (%s)' % \
", ".join([style.SQL_FIELD(qn(opts.get_field(f).column)) for f in field_constraints]))

0 comments on commit e8ddef5

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