Search code examples
djangodjango-south

South not working with Custom Field


I installed this package https://github.com/dracos/django-date-extensions and am using the ApproximateDateField. Everything was working until I tried to convert the app to use South. When I run

manage.py convert_to_south journals 

I get the following error

Creating migrations directory at '/Users/MYID/Projects/MyProjectDir/MyProject/apps/journals/migrations'...
Creating __init__.py in '/Users/MYID/Projects/MyProjectDir/MyProject/apps/journals/migrations'...
 ! Cannot freeze field 'journals.issue.publication_date'
 ! (this field has class django_date_extensions.fields.ApproximateDateField)

 ! 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

I tried adding this to my models file where I use the field but it seem to have no effect

from south.modelsinspector import add_introspection_rules
....
add_introspection_rules([
(
        [ddx.ApproximateDateField],
        [],
        {},
    ),
], ['^south\.tests\.journals\.models\.ApproximateDateField'])

Solution

  • Do you import ApproximateDateField from south.tests.journals.models?

    Seems to me like your regular expression is not matching the custom Field's Class. You need to tell South how to find your custom field, which I'm assuming (I've never used django-date-extensions) you import from:

    django_date_extensions.fields

    With that in mind, you should change this line:

    ['^south\.tests\.journals\.models\.ApproximateDateField']

    to this:

    ['^django_date_extensions\.fields\.ApproximateDateField']