开发者

Loading a fixture before a south migration run

开发者 https://www.devze.com 2023-01-22 11:09 出处:网络
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 ensu

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 or开发者_如何学Cder to do that I need to load data of the old User type before the migration runs. How do I do that?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消