[1.7.x] Fixed #23410 -- Avoided unnecessary rollbacks in related apps when migrating backwards.

Backport of ab2819aa7b09d36d9ff24830a9825aa52b87fdb4 from master.