Opened 10 months ago

Closed 7 months ago

#22831 closed New feature (wontfix)

Migrations should provide a way to dumpdata to an initial data migration

Reported by: gcbirzan Owned by: nobody
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


People with existing south migrations that contain any kind of data migrations will need to dump their initial data in a fixture and re-create it with 1.7 migrations. This is impossible in the current state unless a) there's an undocumented way to do it, b) one uses mock (or monkey patches by hand) to change django.core.serializers.python._get_model to the one from the migration.

The reason that b is needed is because if you modify the model afterwards, loaddata will explode since the model is different.

Additionally, since migrations are now almost 10 times slower than with south, nobody will want to create proper data migrations, so this is really the best way to 'upgrade' from south.

Change History (4)

comment:1 Changed 10 months ago by mjtamlyn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Migrations should provide a way to 'upgrade' from south via loaddata to Migrations should provide a way to dumpdata to an initial data migration
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to New feature
  • Version changed from 1.7-beta-2 to master

I agree there is no current "dumpdata" to get an initial data migration. This would likely be helpful, and is a new feature. It's actually orthogonal to updating from South - any situation where you would previously have done a dumpdata > initial_data.json you now wish to do a dumpdata > initial_migration. I think this feature is likely useful, though the implementation is probably hard and I do not feel its absence is a release blocking issue.

I'm concerned about your comments about migrations speed and upgrading from South. However this ticket is now about adding a new feature to the migrations framework - if you have concerns about migration's performance please raise a separate ticket or open a discussion on django-dev.

comment:2 Changed 10 months ago by gc@…

The implementation should be trivial. Ours, granted, using mock, looks like this:

def loaddata(app_registry, fixture_name):
    from mock import patch
    _get_model = app_registry.get_model

    with patch('django.core.serializers.python._get_model', _get_model):
        from import call_command
        call_command("loaddata", fixture_name)

Obviously, that's a hack, but in a more generic way, this get_model can be passed all the way down to the serializer. Yeah, okay, maybe not exactly trivial, but close enough.

As for the speed... I could open a discussion, sure, but tomorrow.

comment:3 Changed 10 months ago by mardini

#22608 covers migrations slow performance.

comment:4 Changed 7 months ago by andrewgodwin

  • Resolution set to wontfix
  • Status changed from new to closed

I don't see what's being asked for here. Django 1.7 and migrations don't support initial data fixtures, and in addition you're encouraged to do data migrations using the ORM and RunPython rather than calling loaddata (I don't want to have to make loaddata take an Apps object to get the right set of models).

If you have existing South data migrations, you can literally do a find-and-replace to make the same code work inside RunPython - just exchange ormapp.Model? for apps.get_model('app', 'model').

Note: See TracTickets for help on using tickets.
Back to Top