Don't stash references for models not yet in the database.

Review Request #12284 — Created May 16, 2022 and submitted — Latest diff uploaded


Django Evolution


When modifying models that are in the database, we sometimes need to
stash and restore references (constraints). The code that did this would
walk through all fields on all models, looking for anything that pointed
to the model, and would then execute SQL to temporarily remove them or
to introspect them.

This was happening even for models that weren't yet added to the
database, just present in the model registry.

These are now skipped. Only models that are known to be installed now
have their refs stashed.

Encountered this in an upgrade from Review Board 4 -> 5. Verified that
this solved it.

Work is still needed to add unit tests here, but that will come later,
so as not to block current work.