SwiftData Crashes When Using Custom Migration.

I have 2 vesrion schema and Migration plan.

Version 2: Add new properties and Property renamed.

static let release: ModelContainer = {
        do {
            let schema = Schema(versionedSchema: V2Schema.self)
            let appGroupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "***")
            let databaseURL = appGroupURL?.appending(path: "Models.sqlite")
            let databaseName = "Models"
            let configuration = ModelConfiguration(databaseName,
                                                   schema: schema,
                                                   url: databaseURL!,
                                                   cloudKitDatabase: .automatic)            
            return try ModelContainer(for: schema, 
                                      migrationPlan: ModelMigrationPlan.self, 
                                      configurations: [configuration])
        } catch {
            fatalError(error.localizedDescription)
        }
    }()

enum ModelMigrationPlan: SchemaMigrationPlan {
    static var schemas: [VersionedSchema.Type] {
        [V1Schema.self, V2Schema.self]
    }
    
    static var stages: [MigrationStage] {
        [v1ToV2MigrationStage]
    }
    
}

When I test migration in UnitTest, It works fine. But In running in device, error is occurred.

error: Store failed to load.  <NSPersistentStoreDescription: 0x1077aa330> (type: SQLite, url: file:///private/var/mobile/Containers/Shared/AppGroup/***/Model.sqlite) with error = Error Domain=NSCocoaErrorDomain Code=134504 "Cannot use staged migration with an unknown model version." UserInfo={NSLocalizedDescription=Cannot use staged migration with an unknown model version.} with userInfo {
    NSLocalizedDescription = "Cannot use staged migration with an unknown model version.";
}

Has anyone experienced this same problem or know a solution?

Was the original model ever created with a version number?

@MobileTen No original model is made by coredata without version number. I solved problem. (Problem is New swiftdata model was not matched with original model properties.) Thank you ^^

@LeeJaeho can you clarify how you are solving this? I am running up on exactly the same error message.

SwiftData Crashes When Using Custom Migration.
 
 
Q