views:

14

answers:

0

Here is my model definition for a model in a GeoDjango app (with a PostGIS 8.4 database) meant to represent a Chicago neighborhood boundary:

class Neighborhoods(models.Model):
    objectid = models.IntegerField()
    pri_neigh_field = models.CharField(max_length=3)
    pri_neigh = models.CharField(max_length=50)
    sec_neigh_field = models.CharField(max_length=3)
    sec_neigh = models.CharField(max_length=50)
    shape_area = models.FloatField()
    shape_len = models.FloatField()
    geom = models.PolygonField(srid=102671)
    objects = models.GeoManager()

    def __unicode__(self): return self.pri_neigh

In order to get this to work, I had to make a call to add_postgis_srs(102671) from the Django shell and then run "python manage.py reset neighborhoods" to recreate the model tables.

This worked fine for my app, but when I tried to write and run a simple unit test I got the following error as the unit testing framework was setting up the test database:

Installing index for neighborhoods.Neighborhoods model Failed to install index for neighborhoods.Neighborhoods model: AddGeometryColumns() - invalid SRID CONTEXT: SQL statement "SELECT AddGeometryColumn('','', $1 , $2 , $3 , $4 , $5 )" PL/pgSQL function "addgeometrycolumn" line 5 at SQL statement

This is presumably because the test database lacks the appropriate SRID entry in the spatial_ref_sys table.

Is there some way I can tell Django's unit testing framework to add this entry before it creates the tables for my models?