Django: ContentTypes during migration while running tests : <p>I migrated a <code>ForeignKey</code> to a <code>GenericForeignKey</code>, using the <code>contrib.contenttypes</code> framework. To access the <code>ContentType</code> object I need to migrate the data, I used this code:</p>

<pre><code>ContentType = apps.get_model('contenttypes', 'ContentType')

my_model_content_type = ContentType.objects.get(
    app_label='my_app',
    model='my_model'
)
</code></pre>

<p>The migration works when I run <code>manage.py migrate</code>, and I can then play with the updated model in the shell without problems.</p>

<p>However, when I attempt to run <code>manage.py test</code>, I get the following error in the <code>ContentTypes.object.get()</code> line:</p>

<pre><code>__fake__.DoesNotExist: ContentType matching query does not exist.
</code></pre>

<p>Querying for <code>ContentType.objects.all()</code> at that time returns an empty queryset.</p>

<p>I have tried (as directed by another answer here in SO) to run this before my query, but to no avail:</p>

<pre><code>update_contenttypes(apps.app_configs['contenttypes'])
update_contenttypes(apps.app_configs['my_app'])
</code></pre>

<p>How can I ensure that the <code>ContentType</code> rows exist at that point in the test database migration?</p>
