id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux
13826 Impossible to create indexes on PostGIS fields aneil jbronn "I've included a patch which addresses the request below. This adds a signal, final_post_syncdb which enables adding sql commands after all custom sql and indexes and PostGIS columns are created. The patch is with respect to django-trunk
* * *
Please add a ""final_post_syncdb"" signal. See #7561.
It is currently not possible to add custom SQL which depends on GeoDjango fields. This is because the custom sql appears before the commands which create the PostGIS column.
For example, I'd like to create a multicolumn GiST index on Postgres:
in myapp.models.py:
{{{
class Location(Model):
counter = IntegerField()
point = PointField()
}}}
in sql/location.sql:
{{{
CREATE INDEX idx_location_point_counter ON main_location USING GIST(point,counter);
}}}
results in the error:
Failed to install custom SQL for main.Location model: column ""point"" does not exist
(Note, that on Postgres, one needs to install contrib/btree_gist.sql to enable GiST indexes on integer fields)
{{{./manage.py sqlall main }}} yields:
{{{
CREATE TABLE ""main_location"" (
""id"" serial NOT NULL PRIMARY KEY,
""counter"" integer
)
;
CREATE INDEX idx_location_point_counter ON main_location USING GIST(point,counter);
SELECT AddGeometryColumn('main_location', 'point', 4326, 'POINT', 2);
}}}
The problem is in the last two lines: the sql refers to the point column before it's created.
Unfortunately, the post_syncdb signal is no help either, since this is also sent before the PostGIS commands are generated.
" closed GIS 1.2 duplicate Unreviewed 1 0 0 1