Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 671
Gezim Avatar asked Oct 30 '10 02:10

Gezim


1 Answers

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.

like image 80
Evgeny Avatar answered Nov 03 '22 18:11

Evgeny