Fixed #22861: Internal migrations done first so __first__ works

Thanks to Chris Beaven.