[DEV-1965] Update migration logic to use id fields (so it's not confounded by the deletion of the ForeignKey).