<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSMigrationManager/cancelMigrationWithError(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMigrationManager(im)cancelMigrationWithError:"
  },
  "title" : "cancelMigrationWithError(_:)"
}
-->

# cancelMigrationWithError(_:)

Cancels the migration with a given error.

```
func cancelMigrationWithError(_ error: any Error)
```

## Parameters

`error`

An error object that describes the reason why the migration is canceled.

## Discussion

You can invoke this method from anywhere in the migration process to abort the migration. Calling this method causes [`migrateStore(from:sourceType:options:with:toDestinationURL:destinationType:destinationOptions:)`](/documentation/CoreData/NSMigrationManager/migrateStore(from:sourceType:options:with:toDestinationURL:destinationType:destinationOptions:)) to abort the migration and return `error`—you should provide an appropriate error to indicate the reason for the cancellation.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)