Gezim
Gezim

Reputation: 7328

Loading a fixture before a south migration run

I've made a mistake of creating my own User model and am trying to recover.

I've created a south migration that copies my old user models and creates django.contrib.auth.models.User models. To ensure my current users don't get left in the dark, I created a bunch of unittests to ensure everything gets converted appropriately.

So, I need to test the south migration and see if it worked. In order to do that I need to load data of the old User type before the migration runs. How do I do that?

Upvotes: 7

Views: 1785

Answers (2)

Evgeny
Evgeny

Reputation: 10896

When the test suite is run via python manage.py test someapp, first django creates a test database, then applies all migrations in order, then runs test cases. So if the goal is to test the migration itself, you'll need to load fixture data before that migration.

You can add a line or two loading fixture to your migration that applies your model changes just for the sake of testing, then remove.

def forwards(self, orm):
    from django.core import management
    management.call_command('loaddata', 'myfixture.json')
    ... your migration

also, you can add a condition on some made up django setting, then you won't have to edit the code later.

Upvotes: 7

diegueus9
diegueus9

Reputation: 31592

Is called data migrations: http://south.aeracode.org/docs/tutorial/part3.html enjoy!

Upvotes: 0

Related Questions