Post

Replies

Boosts

Views

Activity

Reply to Error message when opening a SwiftData ModelContainer
I am facing the same error in my app. Here is an example of my code to reproduce it. ModelContainer: var sharedModelContainer: ModelContainer = { let modelConfiguration = ModelConfiguration(schema: Schema(versionedSchema: CurrentModelSchema.self), isStoredInMemoryOnly: false) do { let container = try ModelContainer( for: Schema(versionedSchema: CurrentModelSchema.self), migrationPlan: AppMigrationPlan.self, configurations: [modelConfiguration] ) return container } catch { fatalError("Could not create ModelContainer: \(error)") } }() CurrentModelSchema: /// Current model schema typealias CurrentModelSchema = ModelSchemaV3 /// Model references typealias Test1 = CurrentModelSchema.Test1 typealias Test1 = CurrentModelSchema.Test2 The typealiases Test1 and Test2 are @Model-Classes. AppMigrationPlan: enum AppMigrationPlan: SchemaMigrationPlan { static var schemas: [any VersionedSchema.Type] { [ModelSchemaV1.self, ModelSchemaV2.self, ModelSchemaV3.self] } static let migrateV1toV2 = MigrationStage.custom( fromVersion: ModelSchemaV1.self, toVersion: ModelSchemaV2.self, willMigrate: nil, // Logic to perform the migration of V1 schema didMigrate: { context in // Logic to perform the migration of V2 schema let tests = try context.fetch(FetchDescriptor<ModelSchemaV2.Test1>()) // Do the migration operation.... } try context.save() } ) static let migrateV2toV3 = MigrationStage.lightweight( fromVersion: ModelSchemaV2.self, toVersion: ModelSchemaV3.self ) static var stages: [MigrationStage] { // Migration stage that will be performed [migrateV1toV2, migrateV2toV3] } } Please let me know if you need more details to reproduce it.
2w