Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 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.

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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