2

Using the working stuff reported here, I've written the following django model:

from django.contrib.gis.models import SpatialRefSys

class LandCover(models.Model):
    shp_name  = models.CharField(max_length=100)
    geom_srid = models.ForeignKey(SpatialRefSys)

But syncdb gives me this error :

[user@host]$ ./manage.py syncdb
CommandError: One or more models did not validate:
myapp.landcover: 'geom_srid' has a relation with model <class 'django.contrib.gis.db.backends.postgis.models.SpatialRefSys'>, which has either not been installed or is abstract.

Is there a way to solve this?

1

This is a documented behavior as of Django 1.2.

Adding 'django.contrib.gis.db.backends.postgis' to your INSTALLED_APPS should nail it.

| improve this answer | |
  • Thank you. But as reported in django doc, shouldn't be better to use: from django.db import connection SpatialRefSys = connection.ops.spatial_ref_sys() class LandCover(models.Model): shp_name = models.CharField(max_length=100) geom_srid = models.ForeignKey(SpatialRefSys)? This seems to work, or at least ./manage shell does not complain about a non conformant model... – caneta Apr 8 '13 at 7:53
  • Does this work even when you remove 'django.contrib.gis.db.backends.postgis' from your INSTALLED_APPS?It shouldn't since django.contrib.gis.models.SpatialRefSys == connection.ops.spatial_ref_sys() == django.contrib.gis.db.backends.postgis.models.SpatialRefSys when your default connection backends is django.contrib.gis.db.backends.postgis. – Simon Charette Apr 8 '13 at 8:07
  • I didn't add django.contrib.gis.db.backends.postgis to my INSTALLED_APPS variable and I always had django.contrib.gis.db.backends.postgis as my default database engine. But I said "seems" to work because it does not complain when I run ./manage shell...further tests are needed in order to see if this ForeignKey constraint works correctly at all... – caneta Apr 8 '13 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.