1
from MySQLdb.constants import FIELD_TYPE
3
from django.contrib.gis.gdal import OGRGeomType
4
from django.db.backends.mysql.introspection import DatabaseIntrospection
6
class MySQLIntrospection(DatabaseIntrospection):
7
# Updating the data_types_reverse dictionary with the appropriate
8
# type for Geometry fields.
9
data_types_reverse = DatabaseIntrospection.data_types_reverse.copy()
10
data_types_reverse[FIELD_TYPE.GEOMETRY] = 'GeometryField'
12
def get_geometry_type(self, table_name, geo_col):
13
cursor = self.connection.cursor()
15
# In order to get the specific geometry type of the field,
16
# we introspect on the table definition using `DESCRIBE`.
17
cursor.execute('DESCRIBE %s' %
18
self.connection.ops.quote_name(table_name))
19
# Increment over description info until we get to the geometry
21
for column, typ, null, key, default, extra in cursor.fetchall():
23
# Using OGRGeomType to convert from OGC name to Django field.
24
# MySQL does not support 3D or SRIDs, so the field params
26
field_type = OGRGeomType(typ).django
32
return field_type, field_params