Fix migrate function