Fixed #23410 -- Avoid unnecessary rollbacks in related apps when migrating backwards.

Fixed this, and also fixed the set-ordering dependency that caused this test to fail sporadically.