Fix bug in migration while loop.