diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 5f0e278..e6d142b 100644
a
|
b
|
class Command(NoArgsCommand):
|
151 | 151 | field_params['max_length'] = row[3] |
152 | 152 | |
153 | 153 | if field_type == 'DecimalField': |
154 | | field_params['max_digits'] = row[4] |
155 | | field_params['decimal_places'] = row[5] |
| 154 | if not row[4] or not row[5]: |
| 155 | field_notes.append('''max_digits and decimal_places have been guessed, as this database handles decimal fields as float''') |
| 156 | max_digits, decimal_places = 10, 5 |
| 157 | else: |
| 158 | max_digits, decimal_places = row[4], row[5] |
| 159 | field_params['max_digits'] = max_digits |
| 160 | field_params['decimal_places'] = decimal_places |
156 | 161 | |
157 | 162 | return field_type, field_params, field_notes |
158 | 163 | |
diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py
index 9e1518b..b1893d4 100644
a
|
b
|
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
36 | 36 | def get_table_description(self, cursor, table_name): |
37 | 37 | "Returns a description of the table, with the DB-API cursor.description interface." |
38 | 38 | cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)) |
39 | | return cursor.description |
| 39 | # Decimal fields return length + 2, see #5014 |
| 40 | fixed_description = [list(col_info) for col_info in cursor.description] |
| 41 | for col_info in fixed_description: |
| 42 | if col_info[1] in (FIELD_TYPE.DECIMAL, FIELD_TYPE.NEWDECIMAL): |
| 43 | col_info[4] -= 2 |
| 44 | return fixed_description |
40 | 45 | |
41 | 46 | def _name_to_index(self, cursor, table_name): |
42 | 47 | """ |
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index 5ee7b64..d34a06b 100644
a
|
b
|
class FlexibleFieldLookupDict(object):
|
20 | 20 | 'integer unsigned': 'PositiveIntegerField', |
21 | 21 | 'decimal': 'DecimalField', |
22 | 22 | 'real': 'FloatField', |
| 23 | 'numeric': 'FloatField', |
23 | 24 | 'text': 'TextField', |
24 | 25 | 'char': 'CharField', |
25 | 26 | 'date': 'DateField', |
diff --git a/tests/regressiontests/inspectdb/models.py b/tests/regressiontests/inspectdb/models.py
index fc2548b..0111cc5 100644
a
|
b
|
class People(models.Model):
|
6 | 6 | |
7 | 7 | class Message(models.Model): |
8 | 8 | from_field = models.ForeignKey(People, db_column='from_id') |
| 9 | |
| 10 | class DecimalTest(models.Model): |
| 11 | dec_field = models.DecimalField(max_digits=10, decimal_places=5) |
diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py
index 683e6e9..5b5cf39 100644
a
|
b
|
class InspectDBTestCase(TestCase):
|
14 | 14 | self.assertNotIn("from = models.ForeignKey(InspectdbPeople)", out.getvalue(), msg=error_message) |
15 | 15 | self.assertIn("from_field = models.ForeignKey(InspectdbPeople)", out.getvalue()) |
16 | 16 | out.close() |
| 17 | |
| 18 | def test_decimal_field(self): |
| 19 | out = StringIO() |
| 20 | call_command('inspectdb', stdout=out) |
| 21 | self.assertIn("dec_field = models.DecimalField(max_digits=10, decimal_places=5)", out.getvalue()) |