[Django] #22831: Migrations should provide a way to 'upgrade' from south via loaddata

8 views
Skip to first unread message

Django

unread,
Jun 13, 2014, 2:49:47 PM6/13/14
to django-...@googlegroups.com
#22831: Migrations should provide a way to 'upgrade' from south via loaddata
-------------------------------+------------------------
Reporter: gcbirzan | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.7-beta-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22831>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 15, 2014, 5:55:23 AM6/15/14
to django-...@googlegroups.com
#22831: Migrations should provide a way to dumpdata to an initial data migration
-----------------------------+------------------------------------
Reporter: gcbirzan | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by mjtamlyn):

* needs_better_patch: => 0
* needs_tests: => 0
* version: 1.7-beta-2 => master
* needs_docs: => 0
* type: Uncategorized => New feature
* stage: Unreviewed => Accepted


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22831#comment:1>

Django

unread,
Jun 15, 2014, 6:57:23 AM6/15/14
to django-...@googlegroups.com
#22831: Migrations should provide a way to dumpdata to an initial data migration
-----------------------------+------------------------------------
Reporter: gcbirzan | Owner: nobody

Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (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 django.core.management 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22831#comment:2>

Django

unread,
Jun 16, 2014, 5:58:58 AM6/16/14
to django-...@googlegroups.com
#22831: Migrations should provide a way to dumpdata to an initial data migration
-----------------------------+------------------------------------
Reporter: gcbirzan | Owner: nobody

Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by mardini):

#22608 covers migrations slow performance.

--
Ticket URL: <https://code.djangoproject.com/ticket/22831#comment:3>

Django

unread,
Sep 5, 2014, 3:20:58 PM9/5/14
to django-...@googlegroups.com
#22831: Migrations should provide a way to dumpdata to an initial data migration
-----------------------------+------------------------------------
Reporter: gcbirzan | Owner: nobody
Type: New feature | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by andrewgodwin):

* status: new => closed
* resolution: => wontfix


Comment:

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
orm['app.Model'] for apps.get_model('app', 'model').

--
Ticket URL: <https://code.djangoproject.com/ticket/22831#comment:4>

Django

unread,
Nov 25, 2015, 11:07:36 AM11/25/15
to django-...@googlegroups.com
#22831: Migrations should provide a way to dumpdata to an initial data migration
-----------------------------+------------------------------------
Reporter: gcbirzan | Owner: nobody

Type: New feature | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by guettli):

Since this is closed as "wontfix" (which is ok for me), here is a guide
how to do this on your own:

http://stackoverflow.com/a/25981899/633961

--
Ticket URL: <https://code.djangoproject.com/ticket/22831#comment:5>

Django

unread,
Dec 3, 2015, 7:29:53 AM12/3/15
to django-...@googlegroups.com
#22831: Migrations should provide a way to dumpdata to an initial data migration
-----------------------------+------------------------------------
Reporter: gcbirzan | Owner: nobody

Type: New feature | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by MarkusH):

As luckily mentioned on Stackoverflow, all Django implementations that
rely on `django.core.serializers` **will not work reliably** in migrations
as that code will use the models from models.py and not from your
migration state!

--
Ticket URL: <https://code.djangoproject.com/ticket/22831#comment:6>

Reply all
Reply to author
Forward
0 new messages