South migrations for geospatial field typesΒΆ

Tags: django

I wanted to create a south migration for one of my django apps. An app with geospatial field types. Oops:

$> bin/django schemamigration lizard_opendap --initial
 ! Cannot freeze field 'lizard_opendap.point.geom'
 ! (this field has class django.contrib.gis.db.models.fields.PointField)
 ! Cannot freeze field 'lizard_opendap.line.geom'
 ! (this field has class django.contrib.gis.db.models.fields.LineStringField)

 ! South cannot introspect some fields; this is probably because they are custom
 ! fields. If they worked in 0.6 or below, this is because we have removed the
 ! models parser (it often broke things).
 ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork

Weird. I googled a bit and found out that support for those geom fields was added some years ago. So it should work.

The solution: I forgot to add 'django.contrib.gis' to INSTALLED_APPS in settings.py. I thought that entry wasn’t needed anymore, so I tend to leave it out. (Iirc, it used to be necessary because of geospatial databases, but those databases work just fine without adding django.contrib.gis to INSTALLED_APPS now).

Yep, now it works:

$> bin/django schemamigration lizard_opendap --initial
 + Added model lizard_opendap.Setting
 + Added model lizard_opendap.SourceModel
 + Added model lizard_opendap.Scenario
 + Added model lizard_opendap.ModelResult
 + Added model lizard_opendap.Point
 + Added model lizard_opendap.PointValue
 + Added model lizard_opendap.Line
 + Added model lizard_opendap.LineValue
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate lizard_opendap
Old tree
blog comments powered by Disqus
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):