﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19086	Content types and permissions are created for swapped models	Thomas Schreiber	Russell Keith-Magee	"While trying to update django-guardian to support AUTH_USER_MODEL I discovered the contenttypes and permissions are still being created for auth.User 

This means the auth.User app is still being loaded and I've traced the problem to this loop:

[https://github.com/django/django/blob/master/django/db/backends/__init__.py#L998]

If someone could suggest where the correct place to put the check is, I'll be happy to put together a patch and test to reproduce the issue.

I think the following explicit check could work, but it could be better to keep the logic in model._meta for auth.User and check on that instead:
{{{
...
for app in models.get_apps():
    for model in models.get_models(app):
        if ('django.contrib.auth' in settings.INSTALLED_APPS and settings.AUTH_USER_MODEL != 'auth.User' and
            model.__name__ == 'User' and model.__module == 'django.contrib.auth.models'):
            continue
        if not model._meta.managed:
            continue
        if not router.allow_syncdb(self.connection.alias, model):
            continue
        tables.add(model._meta.db_table)
        tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
...
}}}"	Bug	closed	contrib.auth	dev	Release blocker	fixed			Accepted	1	0	1	1	0	0
