'Return a dict of migration plans which will achieve the
change from from_state to to_state. The dict has app labels
as keys and a list of migrations as values.
The resulting migrations aren\'t specially named, but the names
do matter for dependencies inside the set.
convert_apps is the list of apps to convert to use migrations
(i.e. to make initial migrations for, in the usual case)
graph is an optional argument that, if provided, can help improve
dependency generation and avoid potential circular dependencies.'

def _detect_changes(self, convert_apps=None, graph=None):

    self.generated_operations = {}
    self.altered_indexes = {}
    self.old_apps = self.from_state.concrete_apps
    self.new_apps = self.to_state.apps
    self.old_model_keys = []
    self.old_proxy_keys = []
    self.old_unmanaged_keys = []
    self.new_model_keys = []
    self.new_proxy_keys = []
    self.new_unmanaged_keys = []
    for (al, mn) in sorted(self.from_state.models):
        model = self.old_apps.get_model(al, mn)
        if (not model._meta.managed):
            self.old_unmanaged_keys.append((al, mn))
        elif (al not in self.from_state.real_apps):
            if model._meta.proxy:
                self.old_proxy_keys.append((al, mn))
            else:
                self.old_model_keys.append((al, mn))
    for (al, mn) in sorted(self.to_state.models):
        model = self.new_apps.get_model(al, mn)
        if (not model._meta.managed):
            self.new_unmanaged_keys.append((al, mn))
        elif ((al not in self.from_state.real_apps) or (convert_apps and (al in convert_apps))):
            if model._meta.proxy:
                self.new_proxy_keys.append((al, mn))
            else:
                self.new_model_keys.append((al, mn))
    self.generate_renamed_models()
    self._prepare_field_lists()
    self._generate_through_model_map()
    self.generate_deleted_models()
    self.generate_created_models()
    self.generate_deleted_proxies()
    self.generate_created_proxies()
    self.generate_altered_options()
    self.generate_altered_managers()
    self.create_altered_indexes()
    self.generate_removed_indexes()
    self.generate_renamed_fields()
    self.generate_removed_fields()
    self.generate_added_fields()
    self.generate_altered_fields()
    self.generate_altered_unique_together()
    self.generate_altered_index_together()
    self.generate_added_indexes()
    self.generate_altered_db_table()
    self.generate_altered_order_with_respect_to()
    self._sort_migrations()
    self._build_migration_list(graph)
    self._optimize_migrations()
    return self.migrations
