Created
July 23, 2013 01:45
-
-
Save roadsideseb/6059242 to your computer and use it in GitHub Desktop.
Using the 'loaddata' management command in a data migration with South is going to break things as soon as the used models change in any way (when running the migrations on a fresh install). The data loaders don't know about the frozen ORM provided by South but use the current state of the models as in the respective 'models.py'. Here's a fixtur…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from myproject.utils import loaddata | |
class Migration(DataMigration): | |
def forwards(self, orm): | |
loaddata(orm, 'some_fancy_fixture.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def loaddata(orm, fixture_name): | |
""" | |
Overwrite the ``_get_model`` command in the serialiser to use the | |
FakeORM model from south instead of the latest model. | |
""" | |
from dingus import patch | |
_get_model = lambda model_identifier: orm[model_identifier] | |
with patch('django.core.serializers.python._get_model', _get_model): | |
from django.core.management import call_command | |
call_command("loaddata", fixture_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this workaround!