Search code examples
djangodatabase-migrationdjango-south

Django south cannot import required field


I upgraded to django to 1.6.x which no longer has localflavor. localflavor was moved from django.contrib to its own module, which I now use in my app. When I do a schemamigration, south tries to preform this change on the database. (Note: the two modules are very closely related if not entirely similar and are cross compatible.)

The problem is that south still tries to import django.contrib.localflavor, which does not exist.

What is the correct way to fix this?

This is the error I get (running through fabric):

ValueError: Cannot import the required field 'django.contrib.localflavor.us.models.USStateField'

Fatal error: local() encountered an error (return code 1) while executing 'python manage.py migrate --settings=settings.local'

Solution

  • Are you still having this issue? I just ran into this and figured out the solution.

    First open up your latest myapp/migration/0001_blah_blah_blah.py migration for for your app.

    Then find the go to the models dict or just ctrl+f django.contrib.localflavor.us.models.USStateField and replace it with localflavor.us.models.USStateField.

    After that you should be able to run ./manage.py schemamigration myapp --auto successfully and then apply the migration.

    Hope this helps and it's not too late!

    Cheers.