2

I know there are many ways, but I have to add permissions in data migrations.

but when I do,

def add_view_aggregated_data_permissions(apps, schema_editor):
    ContentType = apps.get_model('django', 'ContentType')
    Permission = apps.get_model('auth', 'Permission')
    content_type = ContentType.objects.get(app_label='auth', model='user')
    try
        return Permission.objects.get(codename='can_view_data',
                                       name='Can view data',
                                       content_type=content_type)
    except Permission.DoesNotExist
      # blahblah

When I run the migration, I get __fake __.DoesNotExist: Permission matching query does not exist.

What does this "fake" mean and how can I catch this exception?

PowerLove
  • 303
  • 8
  • 25
  • please post the full stacktrace – lukeaus Aug 17 '16 at 01:26
  • Could I be able to send you the code personally? that would be helpful – PowerLove Aug 17 '16 at 13:12
  • just post the relevant parts in the description - remove anything that is sensitive. That way if other people have a similar problem they can see the solutions :) – lukeaus Aug 17 '16 at 19:52
  • Possible duplicate of [Adding django admin permissions in a migration: Permission matching query does not exist](http://stackoverflow.com/questions/31735042/adding-django-admin-permissions-in-a-migration-permission-matching-query-does-n) – mlissner May 16 '17 at 21:39

0 Answers0