Implement Migration.run_before

This attribute (used for reverse dependencies) was previously declared
and mentioned in the code, but never actually used.
Fixed #20550 -- Added keepdb argument to destroy_test_db
Checked can_introspect_null feature in a test.

Forward-port of 1238f92c from stable/1.7.x.
Replaced an explicit vendor check by a feature flag.

Forward-port of c9aedce0 from stable/1.7.x.
Merge pull request #2736 from SmileyChris/migration-run_before

Fixed #22725 - Migration.run_before does nothing
Rewrote migration autodetector to involve actual computer science.

Fixes #22605, #22735; also lays the ground for some other fixes.
Prevent operation pollution by later operations of fields
Fixed #22773 -- Forced templatize() to return unicode
Merge pull request #2764 from gchp/ticket-20550

Fixed #20550 -- Added keepdb argument to destroy_test_db
Fixed flake8 errors.