Iterators and iterables clarified →

Getting django-south working with gis models

Just a quick note for posterity...

Django's south data migration utility has a weird bug that turned up when I was trying to work with gis fields.

I've been banging my head all day Friday and today against trying to get south working on my geodjango project. My original problem was (I think) that south 0.5 (which is what Karmic installs by default) doesn't set up m2m columns when you do a ./ startmigration app --initial. (this seems to have been fixed three weeks ago in Changeset 548:486840db6350, though I'm not sure that's the right revision) Once I realized that, and upgraded to the latest version (via pip), I had a new problem: South couldn't figure out what do do with my Point column:

jcdyer@aalcdl07:/cgi/django/brp/projects/brp$ ./ startmigration content_base --initial
Creating migrations directory at '/cgi/django/brp/apps/cdla_apps/content_base/migrations'...
Creating in '/cgi/django/brp/apps/cdla_apps/content_base/migrations'...
  + Added model 'content_base.Item'
  + Added model 'content_base.ItemType'
  + Added M2M 'content_base.Item.subject_set'
  + Added M2M 'content_base.Item.date_published_set'
  ( Nodefing field: coordinates
  ( Parsing field: coordinates
WARNING: Cannot get definition for 'coordinates' on 'parkway.location'. Please edit the migration manually to define it, or add the south_field_triple method to it.

It went ahead and created the migration for me, but left some boilerplate for me to clean up in the frozen ORM definition. Where the frozen orm said:

'coordinates': '< < PUT FIELD DEFINITION HERE > >',

I just had to put in the definition of a geometry field. Working from a nearby example that looked like this:

'milepost': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),

I changed my code to:

'coordinates': ('django.contrib.gis.db.models.PointField', [], {'null': 'True', 'blank': 'True'}),

I haven't yet figured out what the south_field_triple method is.

Edit: Bafflingly, there's a PointField on another table in the same app which has no problem defining itself.

Comments !