'Regression test for #22325 - references to a custom user model defined in the
same app are not resolved correctly.'

@override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations_custom_user', 'django.contrib.auth': 'django.contrib.auth.migrations'}, AUTH_USER_MODEL='migrations.Author')
def test_custom_user(self):

    executor = MigrationExecutor(connection)
    self.assertTableNotExists('migrations_author')
    self.assertTableNotExists('migrations_tribble')
    executor.migrate([('migrations', '0001_initial')])
    self.assertTableExists('migrations_author')
    self.assertTableExists('migrations_tribble')
    old_table_names = connection.introspection.table_names
    connection.introspection.table_names = (lambda c: [x for x in old_table_names(c) if (x != 'auth_user')])
    migrations_apps = executor.loader.project_state(('migrations', '0001_initial')).apps
    global_apps.get_app_config('migrations').models['author'] = migrations_apps.get_model('migrations', 'author')
    try:
        migration = executor.loader.get_migration('auth', '0001_initial')
        self.assertIs(executor.detect_soft_applied(None, migration)[0], True)
    finally:
        connection.introspection.table_names = old_table_names
        del global_apps.get_app_config('migrations').models['author']
    executor.loader.build_graph()
    executor.migrate([('migrations', None)])
    self.assertTableNotExists('migrations_author')
    self.assertTableNotExists('migrations_tribble')
