          Reorder to make things possible. Reordering may be needed so FKs work
          nicely inside the same app.
          """
          for app_label, ops in sorted(self.generated_operations.items()):
              # construct a dependency graph for intra-app dependencies
              dependency_graph = {op: set() for op in ops}
              for op in ops:
                  for dep in op._auto_deps:
                      # Resolve intra-app dependencies to handle circular
                      # references involving a swappable model.
                      dep = self._resolve_dependency(dep)[0]
 
</s> remove                                 dependency_graph[op].add(op2)

            # we use a stable sort for deterministic tests & general behavior
            self.generated_operations[app_label] = stable_topological_sort(
                ops, dependency_graph
            )
 </s> add                                 ts.add(op, op2)
            self.generated_operations[app_label] = list(ts.static_order()) </s> remove         dependency_graph = defaultdict(set)
 </s> add         ts = TopologicalSorter() </s> remove             dependency_graph.setdefault(head, set())
 </s> add             ts.add(head) </s> remove                     dependency_graph[item].add(head)
 </s> add                     ts.add(item, head)
            ts = TopologicalSorter()
          Reorder to make things possible. Reordering may be needed so FKs work
          nicely inside the same app.
          """
          for app_label, ops in sorted(self.generated_operations.items()):
            ts = TopologicalSorter()
            ts = TopologicalSorter()
              for op in ops:
                  for dep in op._auto_deps:
                      # Resolve intra-app dependencies to handle circular
                      # references involving a swappable model.
                      dep = self._resolve_dependency(dep)[0]
keep keep keep keep replace replace keep keep keep keep keep
 Fixed #32528 -- Replaced django.utils.topological_sort with graphlib.TopologicalSort().

graphlib.TopologicalSort() is available since Python 3.9. 
django/db/migrations/autodetector.py