Code

Ticket #16455: 16455-v5.diff

File 16455-v5.diff, 1.3 KB (added by fcurella, 2 years ago)
Line 
1diff --git a/django/contrib/gis/db/backends/postgis/creation.py b/django/contrib/gis/db/backends/postgis/creation.py
2index bad22be..1eac429 100644
3--- a/django/contrib/gis/db/backends/postgis/creation.py
4+++ b/django/contrib/gis/db/backends/postgis/creation.py
5@@ -10,6 +10,7 @@ class PostGISCreation(DatabaseCreation):
6         from django.contrib.gis.db.models.fields import GeometryField
7 
8         output = super(PostGISCreation, self).sql_indexes_for_field(model, f, style)
9+        postgis_version = self.connection.ops.spatial_version
10 
11         if isinstance(f, GeometryField):
12             gqn = self.connection.ops.geo_quote_name
13@@ -38,11 +39,11 @@ class PostGISCreation(DatabaseCreation):
14                                   style.SQL_FIELD(qn(f.column)) +
15                                   style.SQL_KEYWORD(' SET NOT NULL') + ';')
16 
17-
18             if f.spatial_index:
19                 # Spatial indexes created the same way for both Geometry and
20                 # Geography columns
21-                if f.geography:
22+                # PostGIS 2.0 does not support GIST_GEOMETRY_OPS
23+                if postgis_version >= (2, 0) or f.geography:
24                     index_opts = ''
25                 else:
26                     index_opts = ' ' + style.SQL_KEYWORD(self.geom_index_opts)