1
0
mirror of https://github.com/django/django.git synced 2025-07-19 17:19:12 +00:00

[1.0.X] Fixed #9862 -- For better SQL portability, don't specify "NULL" 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
This commit is contained in:
Malcolm Tredinnick 2009-01-06 01:57:03 +00:00
parent 7982e5c510
commit e8ddef57d8

View File

@ -47,7 +47,8 @@ class BaseDatabaseCreation(object):
# Make the definition (e.g. 'foo VARCHAR(30)') for this field. # Make the definition (e.g. 'foo VARCHAR(30)') for this field.
field_output = [style.SQL_FIELD(qn(f.column)), field_output = [style.SQL_FIELD(qn(f.column)),
style.SQL_COLTYPE(col_type)] 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: if f.primary_key:
field_output.append(style.SQL_KEYWORD('PRIMARY KEY')) field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
elif f.unique: elif f.unique:
@ -65,8 +66,7 @@ class BaseDatabaseCreation(object):
table_output.append(' '.join(field_output)) table_output.append(' '.join(field_output))
if opts.order_with_respect_to: if opts.order_with_respect_to:
table_output.append(style.SQL_FIELD(qn('_order')) + ' ' + \ table_output.append(style.SQL_FIELD(qn('_order')) + ' ' + \
style.SQL_COLTYPE(models.IntegerField().db_type()) + ' ' + \ style.SQL_COLTYPE(models.IntegerField().db_type()))
style.SQL_KEYWORD('NULL'))
for field_constraints in opts.unique_together: for field_constraints in opts.unique_together:
table_output.append(style.SQL_KEYWORD('UNIQUE') + ' (%s)' % \ table_output.append(style.SQL_KEYWORD('UNIQUE') + ' (%s)' % \
", ".join([style.SQL_FIELD(qn(opts.get_field(f).column)) for f in field_constraints])) ", ".join([style.SQL_FIELD(qn(opts.get_field(f).column)) for f in field_constraints]))