SwiftData migrations allow you to evolve your data models safely as your app updates. Start by defining VersionedSchema for each model version, even your initial one. SwiftData handles lightweight migrations automatically for simple changes like adding optional properties, removing fields, or renaming with @Attribute(originalName:). For complex changes requiring new non-optional fields or data transformations, use SchemaMigrationPlan with custom MigrationStage blocks. The willMigrate closure cleans up old data before schema changes, while didMigrate populates new fields afterward. For major restructuring like splitting models, use a bridge version strategy: keep legacy fields temporarily while populating new structures, then remove them in a subsequent version. Always test migrations with real user data across version skips.
Table of contents
Implementing simple versions with VersionedSchemaAutomatic migration rulesPerforming manual migrations using a migration planSetting up extra complex migrationsSummarySort: