title: Django pytest database access for data migration
body: <p>I'm using <code>Django (1.9.6)</code>, <code>pytest (2.9.2)</code> and <code>pytest-django (2.9.1)</code></p>
  
  <p>I have a data migration that looks like this:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  # Generated by Django 1.9.6 on 2016-06-07 09:56
  from __future__ import unicode_literals
  
  from django.db import migrations
  
  
  def create_groups(apps, schema_editor):
      Group = apps.get_model('auth', 'group')
      Permission = apps.get_model('auth', 'permission')
  
      group1 = Group.objects.create(name='grou1')
      group1_permissions = Permission.objects.filter(codename__in=[
          'add_app1_model',
          'add_app2_model',
          'custom_permission_app1_model'
      ])
      group1.permissions.add(*list(group1_permissions))
  
      group2 = Group.objects.create(name='group2')
      group2_permissions = Permission.objects.get(
          codename='custom_permission_app2_model'    
      )
      group2.permissions.add(*list(group2_permissions))
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('app1', '0001'),
          ('app2', '0001')
      ]
  
      operations = [
          migrations.RunPython(create_groups)
      ]
  </code></pre>
  
  <p>When I execute <code>py.test --create-db</code> all the tests that are marked with <code>pytest.mark.django_db</code> are raising <code>__fake__.DoesNotExist: Permission matching query does not exist.</code> in the <code>get</code> operation of the migration. </p>
  
  <p>Debuging the migrations I found out that the <code>create</code> operations work, but the <code>filter</code> operation always returns empty, my test database has the groups created but no permission is associated to any of the groups. </p>
  
  <p>I don't know if I'm doing something wrong? The temporary fix I did was changing the <code>get</code> to <code>filter</code>, this make the migration execute normally. In the tests I have a fixture that assigns to a user the permissions needed. Because all my code checks against the permissions and not if the user belongs to a groups all my tests pass.</p>