diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py
index e6f18b8..eec69e4 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 | description = list(cursor.description) |
| 40 | |
| 41 | #Fix UTF8 multi-byte charset problem (Ticket #5725) |
| 42 | cursor.execute("SELECT * FROM INFORMATION_SCHEMA.COLUMNS \ |
| 43 | WHERE table_name = '%s' AND table_schema = DATABASE()" % (table_name, )) |
| 44 | |
| 45 | new_info = cursor.fetchall() |
| 46 | |
| 47 | for i, field in enumerate(description): |
| 48 | if field[1] == 253 and new_info[i][8] is not None: #character varying |
| 49 | field = list(field) #Turn mutable |
| 50 | field[3] = int(new_info[i][8]) |
| 51 | description[i] = field |
| 52 | |
| 53 | return description |
40 | 54 | |
41 | 55 | def _name_to_index(self, cursor, table_name): |
42 | 56 | """ |
diff --git a/tests/regressiontests/introspection/tests.py b/tests/regressiontests/introspection/tests.py
index ca58f04..d546bcf 100644
a
|
b
|
class IntrospectionTests(TestCase):
|
89 | 89 | [datatype(r[1], r) for r in desc], |
90 | 90 | ['IntegerField', 'CharField', 'CharField', 'CharField', 'BigIntegerField'] |
91 | 91 | ) |
| 92 | |
| 93 | |
| 94 | def test_get_table_description_types_varchar_length(self): |
| 95 | |
| 96 | cursor = connection.cursor() |
| 97 | cursor.execute("""CREATE TABLE django_ixn_test_table_varchars ( |
| 98 | id INT NOT NULL , |
| 99 | name VARCHAR(45) NULL , |
| 100 | other_charfield VARCHAR(128) NULL );""") |
| 101 | |
| 102 | desc = connection.introspection.get_table_description( cursor, "django_ixn_test_table_varchars" ) |
| 103 | cursor.execute("DROP TABLE django_ixn_test_table_varchars;") |
| 104 | |
| 105 | self.assertEqual( |
| 106 | [ field_desc[3] if field_desc[1]==253 else None for field_desc in desc], |
| 107 | [ None, 45, 128 ] |
| 108 | ) |
92 | 109 | |
93 | 110 | # Oracle forces null=True under the hood in some cases (see |
94 | 111 | # https://docs.djangoproject.com/en/dev/ref/databases/#null-and-empty-strings) |