Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19341 -- Detected NullBooleanField when introspecting models

Thanks Tim Bowden for the report.
  • Loading branch information...
commit 7bbd17bf20e46283954aead2750c24642fd8d9f9 1 parent 3c0a81a
@claudep claudep authored
View
9 django/core/management/commands/inspectdb.py
@@ -108,9 +108,12 @@ def handle_inspection(self, options):
# Add 'null' and 'blank', if the 'null_ok' flag was present in the
# table description.
if row[6]: # If it's NULL...
- extra_params['blank'] = True
- if not field_type in ('TextField(', 'CharField('):
- extra_params['null'] = True
+ if field_type == 'BooleanField(':
+ field_type = 'NullBooleanField('
+ else:
+ extra_params['blank'] = True
+ if not field_type in ('TextField(', 'CharField('):
+ extra_params['null'] = True
field_desc = '%s = models.%s' % (att_name, field_type)
if extra_params:
View
2  tests/regressiontests/inspectdb/models.py
@@ -34,6 +34,7 @@ class ColumnTypes(models.Model):
id = models.AutoField(primary_key=True)
field1 = models.BigIntegerField()
field2 = models.BooleanField()
+ field2b = models.NullBooleanField()
field3 = models.CharField(max_length=10)
field4 = models.CommaSeparatedIntegerField(max_length=99)
field5 = models.DateField()
@@ -46,7 +47,6 @@ class ColumnTypes(models.Model):
field12 = models.IntegerField()
field13 = models.IPAddressField()
field14 = models.GenericIPAddressField(protocol="ipv4")
- field15 = models.NullBooleanField()
field16 = models.PositiveIntegerField()
field17 = models.PositiveSmallIntegerField()
field18 = models.SlugField()
View
4 tests/regressiontests/inspectdb/tests.py
@@ -39,8 +39,10 @@ def assertFieldType(name, definition):
if connection.vendor == 'mysql':
# No native boolean type on MySQL
assertFieldType('field2', "models.IntegerField()")
+ assertFieldType('field2b', "models.IntegerField(null=True, blank=True)")
else:
assertFieldType('field2', "models.BooleanField()")
+ assertFieldType('field2b', "models.NullBooleanField()")
assertFieldType('field3', "models.CharField(max_length=10)")
# CommaSeparatedIntegerField
assertFieldType('field4', "models.CharField(max_length=99)")
@@ -68,8 +70,6 @@ def assertFieldType(name, definition):
else:
assertFieldType('field13', "models.CharField(max_length=15)")
assertFieldType('field14', "models.CharField(max_length=39)")
- # Ticket #19341
- #assertFieldType('field15', "models.NullBooleanField()")
if connection.vendor == 'sqlite':
assertFieldType('field16', "models.PositiveIntegerField()")
assertFieldType('field17', "models.PositiveSmallIntegerField()")
Please sign in to comment.
Something went wrong with that request. Please try again.