fromMySQLdb.constantsimportFIELD_TYPEfromdjango.contrib.gis.gdalimportOGRGeomTypefromdjango.db.backends.mysql.introspectionimportDatabaseIntrospectionclassMySQLIntrospection(DatabaseIntrospection):# Updating the data_types_reverse dictionary with the appropriate# type for Geometry fields.data_types_reverse=DatabaseIntrospection.data_types_reverse.copy()data_types_reverse[FIELD_TYPE.GEOMETRY]="GeometryField"defget_geometry_type(self,table_name,description):withself.connection.cursor()ascursor:# In order to get the specific geometry type of the field,# we introspect on the table definition using `DESCRIBE`.cursor.execute("DESCRIBE %s"%self.connection.ops.quote_name(table_name))# Increment over description info until we get to the geometry# column.forcolumn,typ,null,key,default,extraincursor.fetchall():ifcolumn==description.name:# Using OGRGeomType to convert from OGC name to Django field.# MySQL does not support 3D or SRIDs, so the field params# are empty.field_type=OGRGeomType(typ).djangofield_params={}breakreturnfield_type,field_paramsdefsupports_spatial_index(self,cursor,table_name):# Supported with MyISAM/Aria, or InnoDB on MySQL 5.7.5+/MariaDB.storage_engine=self.get_storage_engine(cursor,table_name)ifstorage_engine=="InnoDB":ifself.connection.mysql_is_mariadb:returnTruereturnself.connection.mysql_version>=(5,7,5)returnstorage_enginein("MyISAM","Aria")