[1.7.x] Fixed #22861: Internal migrations done first so __first__ works

Thanks to Chris Beaven.