---
title: Migrate model versions from Workspace Model Registry to Unity Catalog | Databricks on AWS
source: https://docs.databricks.com/aws/en/machine-learning/manage-model-lifecycle/migrate-models
ingestedAt: "2026-06-18T08:11:23.469Z"
---

    import mlflowfrom mlflow import MlflowClientfrom mlflow.exceptions import MlflowExceptionfrom mlflow.models import ModelSignaturefrom mlflow.types.schema import Schema, ColSpec, AnyTypemlflow.set_registry_uri("databricks")workspace_client = MlflowClient(registry_uri="databricks")uc_client = MlflowClient(registry_uri="databricks-uc")# Make a placeholder model that can be used to increment the version numberdef make_placeholder_model() -> str:    class _Placeholder(mlflow.pyfunc.PythonModel):        def predict(self, ctx, x):            return None    with mlflow.start_run() as run:        schema = Schema([ColSpec(AnyType())])        model = mlflow.pyfunc.log_model(            name="m",            python_model=_Placeholder(),            signature=ModelSignature(inputs=schema, outputs=schema),        )        return f"models:/{model.model_id}"# Check if the source model has a particular version numberdef workspace_model_exists(name: str, version: int) -> bool:    try:        workspace_client.get_model_version(name, str(version))        return True    except MlflowException as e:        if e.error_code == "RESOURCE_DOES_NOT_EXIST":            # Convert the RESOURCE_DOES_NOT_EXIST error into False            return False        # Raise all other exceptions        raise e# Copy model versions from a source Databricks workspace-registered model to# a destination Databricks Unity Catalog registered modeldef copy_model_versions_to_uc(src: str, dst: str) -> None:    latest_versions = workspace_client.get_latest_versions(src)    max_version_number = max(int(v.version) for v in latest_versions)    placeholder_model = make_placeholder_model()    for v in range(1, max_version_number + 1):        if workspace_model_exists(src, v):            workspace_client.copy_model_version(f"models:/{src}/{str(v)}", dst)        else:            # Create and immediately delete a placeholder model version to increment            # the version counter on the UC model, so the version numbers on the UC            # model match those on the workspace registered model.            mv = uc_client.create_model_version(dst, placeholder_model)            uc_client.delete_model_version(dst, mv.version)copy_model_versions_to_uc("my_workspace_model", "mycatalog.myschema.my_uc_model")
