Skip to content

Instantly share code, notes, and snippets.

@roadsideseb
Created July 23, 2013 01:45
Show Gist options
  • Save roadsideseb/6059242 to your computer and use it in GitHub Desktop.
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…
from myproject.utils import loaddata
class Migration(DataMigration):
def forwards(self, orm):
loaddata(orm, 'some_fancy_fixture.json')
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)
@npardington
Copy link

Thanks for this workaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment