Impossible to create indexes on PostGIS fields
|Reported by:||aneil||Owned by:||jbronn|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Description (last modified by 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:
class Location(Model): counter = IntegerField() point = PointField()
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.
Change History (5)
Changed 6 years ago by aneil
comment:1 Changed 6 years ago by jbronn
- Description modified (diff)
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 6 years ago by jbronn
- Owner changed from nobody to jbronn
- Patch needs improvement set
- Status changed from new to assigned