You don't need the temporary field.
1) create the "through" model, add it to the migration file
2) migrate all m2m instances (e.g. iterate over all Bereich objects then iterate through its users, creating a UserBereichAssignment object for each (all this done in a migrations.RunPython call)
3) change the m2m field by adding the through option, and add this change to the migrations file.
However, you may want to go with django-guardian and thus, with object-level permissions instead ;)
--
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...@googlegroups.com.
To post to this group, send email to django...@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/55A7BA3E.5030105%40cafu.de.
For more options, visit https://groups.google.com/d/optout.
hey hi,
Am 2015-07-16 um 18:15 schrieb Gergely Polonkai:
> 1) create the "through" model, add it to the migration file
> 2) migrate all m2m instances (e.g. iterate over all Bereich objects then
> iterate through its users, creating a UserBereichAssignment object for
> each (all this done in a migrations.RunPython call)
Ok. I've never used migrations.RunPython before, but I'm quite confident
that I can manage it.
Would the migration for step 2) be a separate migration file from step
1), or is the migration file of step 1) edited to cover step 2) as well?
> 3) change the m2m field by adding the through option, and add this
> change to the migrations file.
Same question: Is this supposed to go into a separate migration file or
into the common migrations file from above?
And won't this last step trigger the same error as before? ("... you
cannot alter to or from M2M fields, or add or remove through= on M2M
fields") ?
(Not so important, but out of curiosity: This won't get us rid of the
old, implicit intermediate table, will it?)
Hello,
I'm sorry, I was not around my mailbox lately.
Yes, you are right, my attempt is not the solution to your problem; it seems that this m2m field really cannot be modified like this. With some slight modifications, though, it may be.
1) create the through table
2) migrate data with RunPython — if you want to be portable, stay with RunPython instead of RunSQL
3) delete the ManyToManyField
4) recreate the ManyToManyField with the through option
All this can (and I think, should) go into the same migration file. Meanwhile it might worth a question to the devs (or a more thorough search on the topic) to understand why you can't switch from a simple m2m field to one with a through option.
Best,
Gergely
--
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...@googlegroups.com.
To post to this group, send email to django...@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/55B11F7B.1010805%40cafu.de.