---
title: NSPersistentStoreDeferredLightweightMigrationOptionKey
framework: coredata
role: symbol
role_heading: Global Variable
path: coredata/nspersistentstoredeferredlightweightmigrationoptionkey
---

# NSPersistentStoreDeferredLightweightMigrationOptionKey

The key for enabling deferred lightweight migrations.

## Declaration

```swift
let NSPersistentStoreDeferredLightweightMigrationOptionKey: String
```

## Discussion

Discussion As your managed object model changes, Core Data can use lightweight migrations to synchronize the underlying store data with those evolving entity definitions. These migrations happen at runtime, so they need to be fast or they can lead to a poor experience, because a migration must complete before your app can continue. Reduce the impact of migrations by deferring expensive cleanup tasks — such as dropping a table — until a more opportune time. important: This key is dual-purpose. When adding a persistent store to the coordinator, you use it to enable deferred lightweight migrations for that store. Afterward, Core Data uses it to indicate whether there are deferred cleanup tasks to run. Therefore, don’t use this key to later determine whether you enabled deferred lightweight migrations on a specific store. Deferred lightweight migrations are off by default. To enable them, add NSPersistentStoreDeferredLightweightMigrationOptionKey, with a value of true, to the options dictionary you provide when adding a persistent store to the coordinator. let options = [     // Enable deferred lightweight migrations.     NSPersistentStoreDeferredLightweightMigrationOptionKey: true,     // Enable lightweight migrations.     NSMigratePersistentStoresAutomaticallyOption: true,     NSInferMappingModelAutomaticallyOption: true ]          let store = coordinator.addPersistentStore(     type: .sqlite,     at: storeURL,     options: options ) After you enable deferred lightweight migrations, Core Data continues to perform your lightweight migrations as usual, but defers any time-consuming cleanup tasks that don’t impact the execution of your app. Those tasks still need to run, but you choose when to run them. To determine whether there are deferred tasks to finish, query the store’s metadata with NSPersistentStoreDeferredLightweightMigrationOptionKey. If the returned value is true, execute those tasks using the coordinator. A single migration may defer several distinct tasks and you can execute them all at once using finishDeferredLightweightMigration(), or individually using finishDeferredLightweightMigrationTask(). let key = NSPersistentStoreDeferredLightweightMigrationOptionKey if let hasMigration = store.metadata[key], hasMigration == true {     coordinator.finishDeferredLightweightMigration() }

## See Also

### Deferring a store’s migrations

- [finishDeferredLightweightMigrationTask()](coredata/nspersistentstorecoordinator/finishdeferredlightweightmigrationtask().md)
- [finishDeferredLightweightMigration()](coredata/nspersistentstorecoordinator/finishdeferredlightweightmigration().md)
