Craig Blaszczyk
Craig Blaszczyk

Reputation: 972

Django 1.3 and South migrations

I have an existing project which extensively uses South migrations to load data into its tables.

Since upgrading to Django 1.3 our unit tests no longer run because they cannot find the data they rely on.

  1. Is this behaviour is due to one of the backwards incompatible changes in 1.3
  2. Is there an easy way for me to convert all these migrations into fixtures?

Upvotes: 6

Views: 910

Answers (2)

RemcoGerlich
RemcoGerlich

Reputation: 31260

I hit this issue today. Eventually I ended up refactoring my migrations so that they use helper functions to actually insert the data, and then calling the same functions from the setUp() of my tests.

Some hints;

  • Make your helper functions take the model class as an argument, so you can call them with orm['yourapp.YourModel'] from the migration and with models.YourModel from the test. That also shows the main limitation: South works for models whose schema has changed since then, the test code can't do that. I was lucky in that this particular model hasn't changed.

  • If you want to keep the helper methods inside the migrations, you'll find that you can't directly import yourapp.migrations.0001_some_migration because identifiers can't start with numbers. Use something like migration_0001 = importlib.import_module('yourapp.migrations.0001_some_migration') instead of an import statement.

Upvotes: 0

Mikhail Korobov
Mikhail Korobov

Reputation: 22238

  1. Yes, this behavior is due to this change.

    There seems to be a workaround in South trunk (see https://bitbucket.org/andrewgodwin/south/changeset/21a635231327 ) so you can try South development version (it is quite stable in my experience).

  2. You may try to change the DB name in settings (in order to get clean environment), run ./manage.py syncdb and ./manage.py migrate and then do ./manage.py dumpdata

Upvotes: 3

Related Questions