Unfortunately, the OGC specification requires that the geometry column is added via the AddGeometryColumn
stored procedure after the table is defined. There are a few options here:
(1) Modify so that unique_together
with geometry columns is created by an ALTER TABLE
statement after AddGeometryColumn
is called. I think this would require a good amount of re-plumbing in django.db.backends.creation.BaseDatabaseCreation.sql_create_model
and possibly some flag on Field
itself to indicate which fields are added outside the CREATE TABLE
definition.
(2) Use PostGIS 1.5 and the geography
column type (which is a normal db column type and put in CREATE TABLE
statement, unlike the geometry
type). In other words, X = models.PointField(geography=True, null=True, blank=True)
. This also requires Django 1.2 (or SVN), but you'd be able to use the constraint.
(3) Use another database backend, like MySQL or Oracle, that doesn't create geometries with the AddGeometryColumn
stored procedure.
Obviously, (1) is a long-term fix, while (2) and (3) are workarounds for the moment. This is definitely a DDN ticket for the moment.