Friday, April 24, 2015

Re: Slowness of the resulting squashed migration

Hi,

In principle it is possible to write your own or modify existing migrations unless they are already applied.

Regarding the additional AddField() operations: in case you have e.g. circular references between two models Django cannot add both models with their full columns at the same time. Django first adds one model without the ForeignKey, then the second model including the FK to the first model and finally adds the field to the first model pointing to the second model [1]. Bottom line: if you find a way to optimize something in your squashed migration, feel free to go ahead. It would be helpful if you report this as an enhance to our issue tracker [2] so we can include a possible improvement in future Django versions.

/Markus

[1] Have a look at slide 14f of https://speakerdeck.com/andrewgodwin/migrations-under-the-hood
[2] https://code.djangoproject.com/

On Friday, April 24, 2015 at 8:14:34 PM UTC+2, aRkadeFR wrote:
Hello,

After working on a project and having around 10 migrations per app,
I wanted to refactor some migrations (of the same app) into only one
and have a faster migrations while testing.

I did squashmigrations on many of the migrations, but the resulting
squased migration is still pretty slow (around 6 seconds to create 4
tables on MySQL 5.5 without any data inserted).

After looking at the migrations, there is some CreateModel(name='XXXX')
and after the table creation some AddField on the same table/models...

I would like to know if it's safe to change the migrations by hand? Is
there a reason the squashmigrations didn't refactor into only CreateModel
without AddField then?

Thanks

aRkadeFR

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c75633dd-b41a-46af-9e72-ced31e2e6885%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment