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.
This commit is contained in:
Claude Paroz 2013-04-01 18:32:57 +02:00
parent 51028f50b6
commit dcf563071f
2 changed files with 12 additions and 4 deletions

View File

@ -213,8 +213,15 @@ class Command(NoArgsCommand):
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 File

@ -55,8 +55,9 @@ class InspectDBTestCase(TestCase):
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)")