'Create a project state including all the applications without
migrations and applied migrations if with_applied_migrations=True.'

def _create_project_state(self, with_applied_migrations=False):

    state = ProjectState(real_apps=list(self.loader.unmigrated_apps))
    if with_applied_migrations:
        full_plan = self.migration_plan(self.loader.graph.leaf_nodes(), clean_start=True)
        applied_migrations = {self.loader.graph.nodes[key] for key in self.loader.applied_migrations if (key in self.loader.graph.nodes)}
        for (migration, _) in full_plan:
            if (migration in applied_migrations):
                migration.mutate_state(state, preserve=False)
    return state
