From 4fe6824ffd319b199140e291f0f742e7fe1f4615 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 20 Oct 2014 20:05:43 +0200 Subject: [PATCH] Fixed #23679 -- Fixed null introspection for char/text fields Thanks Paul Dejean for the report. --- django/core/management/commands/inspectdb.py | 3 +-- tests/inspectdb/models.py | 1 + tests/inspectdb/tests.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index 52c3ac5a25..32ee23581d 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -123,8 +123,7 @@ class Command(BaseCommand): field_type = 'NullBooleanField(' else: extra_params['blank'] = True - if field_type not in ('TextField(', 'CharField('): - extra_params['null'] = True + extra_params['null'] = True field_desc = '%s = %s%s' % ( att_name, diff --git a/tests/inspectdb/models.py b/tests/inspectdb/models.py index d55b457abe..6e4ce02758 100644 --- a/tests/inspectdb/models.py +++ b/tests/inspectdb/models.py @@ -50,6 +50,7 @@ class ColumnTypes(models.Model): bool_field = models.BooleanField(default=False) null_bool_field = models.NullBooleanField() char_field = models.CharField(max_length=10) + null_char_field = models.CharField(max_length=10, blank=True, null=True) comma_separated_int_field = models.CommaSeparatedIntegerField(max_length=99) date_field = models.DateField() date_time_field = models.DateTimeField() diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 708bae4fb8..e35fe0bd48 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -51,6 +51,7 @@ class InspectDBTestCase(TestCase): if (connection.features.can_introspect_max_length and not connection.features.interprets_empty_strings_as_nulls): assertFieldType('char_field', "models.CharField(max_length=10)") + assertFieldType('null_char_field', "models.CharField(max_length=10, blank=True, null=True)") assertFieldType('comma_separated_int_field', "models.CharField(max_length=99)") assertFieldType('date_field', "models.DateField()") assertFieldType('date_time_field', "models.DateTimeField()")