diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-04-01 18:17:00 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-04-01 18:17:00 +0200 |
| commit | 51028f50b624efae273dcbe828ec80c1846c74dc (patch) | |
| tree | 97b4ef2a0a24a4520b269b3154a77d5e1fbd0aea | |
| parent | a01361b5ae9df5220c0ce7b42c5ff36094d5718c (diff) | |
Fixed getting max_digits for MySQL decimal fields
Refs #5014.
| -rw-r--r-- | django/db/backends/mysql/introspection.py | 11 | ||||
| -rw-r--r-- | tests/inspectdb/tests.py | 2 |
2 files changed, 10 insertions, 3 deletions
diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py index 0be99e08bb..3e3b7808c2 100644 --- a/django/db/backends/mysql/introspection.py +++ b/django/db/backends/mysql/introspection.py @@ -47,8 +47,17 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): AND character_maximum_length IS NOT NULL""", [table_name]) length_map = dict(cursor.fetchall()) + # Also getting precision and scale from information_schema (see #5014) + cursor.execute(""" + SELECT column_name, numeric_precision, numeric_scale FROM information_schema.columns + WHERE table_name = %s AND table_schema = DATABASE() + AND data_type='decimal'""", [table_name]) + numeric_map = dict([(line[0], tuple([int(n) for n in line[1:]])) for line in cursor.fetchall()]) + cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name)) - return [FieldInfo(*(line[:3] + (length_map.get(line[0], line[3]),) + line[4:])) + return [FieldInfo(*(line[:3] + (length_map.get(line[0], line[3]),) + + numeric_map.get(line[0], line[4:6]) + + (line[6],))) for line in cursor.description] def _name_to_index(self, cursor, table_name): diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 0f0542279d..1544955476 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -57,8 +57,6 @@ class InspectDBTestCase(TestCase): if connection.vendor == 'sqlite': # Ticket #5014 assertFieldType('decimal_field', "models.DecimalField(max_digits=None, decimal_places=None)") - elif connection.vendor == 'mysql': - pass # Ticket #5014 else: assertFieldType('decimal_field', "models.DecimalField(max_digits=6, decimal_places=1)") assertFieldType('email_field', "models.CharField(max_length=75)") |
