Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@claudep claudep authored
View
11 django/core/management/commands/inspectdb.py
@@ -213,8 +213,15 @@ def get_field_type(self, connection, table_name, row):
field_params['max_length'] = int(row[3])
if field_type == 'DecimalField':
- field_params['max_digits'] = row[4]
- field_params['decimal_places'] = row[5]
+ if row[4] is None or row[5] is None:
+ field_notes.append(
+ 'max_digits and decimal_places have been guessed, as this '
+ 'database handles decimal fields as float')
+ field_params['max_digits'] = row[4] if row[4] is not None else 10
+ field_params['decimal_places'] = row[5] if row[5] is not None else 5
+ else:
+ field_params['max_digits'] = row[4]
+ field_params['decimal_places'] = row[5]
return field_type, field_params, field_notes
View
5 tests/inspectdb/tests.py
@@ -55,8 +55,9 @@ def assertFieldType(name, definition):
assertFieldType('date_field', "models.DateField()")
assertFieldType('date_time_field', "models.DateTimeField()")
if connection.vendor == 'sqlite':
- # Ticket #5014
- assertFieldType('decimal_field', "models.DecimalField(max_digits=None, decimal_places=None)")
+ # Guessed arguments, see #5014
+ assertFieldType('decimal_field', "models.DecimalField(max_digits=10, decimal_places=5) "
+ "# max_digits and decimal_places have been guessed, as this database handles decimal fields as float")
else:
assertFieldType('decimal_field', "models.DecimalField(max_digits=6, decimal_places=1)")
assertFieldType('email_field', "models.CharField(max_length=75)")

0 comments on commit dcf5630

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