Thanks for the answer.

Right now, I just know that after squashing some migrations,
it created a squashed migrations with CreateModel + AlterField
and AddField after that runs on 5seconds, and now that I put
all the field in the CreateModel without any AlterField or AddField,
it runs on <2secondes.

I had some custom RunPython function in the migrations but
removed it for the squashing.

I will dig a bit more and open a ticket if I can reproduce it :)

Have a good day

On 04/24/2015 09:09 PM, Markus Holtermann wrote:
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+unsubscr...@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/553E0EFE.60902%40arkade.info.
For more options, visit https://groups.google.com/d/optout.

Reply via email to