diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py index 42cc9c5dfe..dc26bb11d2 100644 --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -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 diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 1544955476..39685484a2 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -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)")