Fixed #22319 -- Fixed migration external dependencies when there are internal dependencies.