Browse Source

Fixed #23679 -- Fixed null introspection for char/text fields

Thanks Paul Dejean for the report.
Claude Paroz 10 years ago
parent
commit
4fe6824ffd

+ 1 - 2
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,

+ 1 - 0
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()

+ 1 - 0
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()")