Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5014 -- Guessed max_digits and decimal_places for SQLite

Decimal is treated as float on SQLite, hence inspectdb can only
guess max_digits and decimal_places arguments.
  • Loading branch information...
commit dcf563071fad7fe286c6921c949639fc99f51351 1 parent 51028f5
Claude Paroz authored April 01, 2013
11  django/core/management/commands/inspectdb.py
@@ -213,8 +213,15 @@ def get_field_type(self, connection, table_name, row):
213 213
             field_params['max_length'] = int(row[3])
214 214
 
215 215
         if field_type == 'DecimalField':
216  
-            field_params['max_digits'] = row[4]
217  
-            field_params['decimal_places'] = row[5]
  216
+            if row[4] is None or row[5] is None:
  217
+                field_notes.append(
  218
+                    'max_digits and decimal_places have been guessed, as this '
  219
+                    'database handles decimal fields as float')
  220
+                field_params['max_digits'] = row[4] if row[4] is not None else 10
  221
+                field_params['decimal_places'] = row[5] if row[5] is not None else 5
  222
+            else:
  223
+                field_params['max_digits'] = row[4]
  224
+                field_params['decimal_places'] = row[5]
218 225
 
219 226
         return field_type, field_params, field_notes
220 227
 
5  tests/inspectdb/tests.py
@@ -55,8 +55,9 @@ def assertFieldType(name, definition):
55 55
         assertFieldType('date_field', "models.DateField()")
56 56
         assertFieldType('date_time_field', "models.DateTimeField()")
57 57
         if connection.vendor == 'sqlite':
58  
-            # Ticket #5014
59  
-            assertFieldType('decimal_field', "models.DecimalField(max_digits=None, decimal_places=None)")
  58
+            # Guessed arguments, see #5014
  59
+            assertFieldType('decimal_field', "models.DecimalField(max_digits=10, decimal_places=5) "
  60
+                "# max_digits and decimal_places have been guessed, as this database handles decimal fields as float")
60 61
         else:
61 62
             assertFieldType('decimal_field', "models.DecimalField(max_digits=6, decimal_places=1)")
62 63
         assertFieldType('email_field', "models.CharField(max_length=75)")

0 notes on commit dcf5630

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