[1.7.x] Reordered condition to avoid calling allow_migrate() if unneeded.

Backport of 82aca216e130973d142473ebb4b22d1eae146ec7 from master