#23422: Cannot add Permission to Group in data migration
----------------------------+--------------------------------------
     Reporter:  tjwalch     |                    Owner:  nobody
         Type:  Bug         |                   Status:  closed
    Component:  Migrations  |                  Version:  1.7
     Severity:  Normal      |               Resolution:  wontfix
     Keywords:              |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+--------------------------------------

Comment (by frnhr):

 The solution jwhitlock proposes with calling `create_permissions` from
 migration fixed one of my problematic migration, but not another. The
 other migration is calling `loaddata` command to do a one-time fixture
 import, and it was failing because required `ContentType` objects haven't
 been created. So it seems to be another face of the same problem.

 Here is a more dirty workaround until an official solution becomes
 available. I think it has better changes of fixing the problem in case
 solution with `create_permissions` fails:

 {{{
 if ContentType.objects.filter(**whats_needed_for_this_migration).count() <
 1:
     print("Running another migrate command from migration to create
 ContentType objects:")
     call_command('migrate', 'users', '0002')  # this should cite migration
 from the same app, just prior to this one
     print("Finished with the migrate command.")
 }}}

 I'm guessing the only thing really needed from the `migrate` management
 command in this situation is:

 {{{
 emit_post_migrate_signal(created_models, self.verbosity, self.interactive,
 connection.alias)
 }}}

 but not sure how to populate the arguments.

 I have no idea if using `call_command("migrate")` from a migration (of all
 places...) can be problematic, but in my particular case there don't seem
 to be any problems.

 The lengths we have to go to... Please **willfix** this.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.b290e33d3704cfa2f7269984ff4d0e65%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to