1 from django
.db
.backends
.mysql
.creation
import DatabaseCreation
3 class MySQLCreation(DatabaseCreation
):
5 def sql_indexes_for_field(self
, model
, f
, style
):
6 from django
.contrib
.gis
.db
.models
.fields
import GeometryField
7 output
= super(MySQLCreation
, self
).sql_indexes_for_field(model
, f
, style
)
9 if isinstance(f
, GeometryField
) and f
.spatial_index
:
10 qn
= self
.connection
.ops
.quote_name
11 db_table
= model
._meta
.db_table
12 idx_name
= '%s_%s_id' % (db_table
, f
.column
)
13 output
.append(style
.SQL_KEYWORD('CREATE SPATIAL INDEX ') +
14 style
.SQL_TABLE(qn(idx_name
)) +
15 style
.SQL_KEYWORD(' ON ') +
16 style
.SQL_TABLE(qn(db_table
)) + '(' +
17 style
.SQL_FIELD(qn(f
.column
)) + ');')