Home > Code > Getting django-south working with gis models.

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 ./manage.py 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$ ./manage.py startmigration content_base --initial
Creating migrations directory at '/cgi/django/brp/apps/cdla_apps/content_base/migrations'...
Creating __init__.py 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.
Created 0001_initial.py.

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.

Categories: Code
  1. 2009/12/15 at 8:53 pm

    Yup, I can honestly I say I’m completely befuddled by everything you said up there. Hope it works out for you though :-)

  2. Cliff
    2010/01/04 at 1:47 pm

    The problem was, infuriatingly enough, that the models file didn’t end with a newline. I need to look into Wing’s configuration options and sort this out. Bug report submitted.

    • ZdenekSoftic
      2010/02/17 at 7:47 am

      Thank you Cliff for sharing this. You helped me a lot. That nasty newline… :)

  1. No trackbacks yet.

Leave a reply to Cliff Cancel reply