SwiftData migration error

CrashLog

Distributor ID:      com.apple.AppStore
Hardware Model:      iPhone15,3
Process:             DeadLineTodo [5556]
Path:                /private/var/containers/Bundle/Application/348CC8D5-05FD-41DF-93A3-C15562EF4AA8/DeadLineTodo.app/DeadLineTodo
Identifier:          andy.DeadLineTodo
Version:             2.4.0 (3)
AppStoreTools:       15F31e
AppVariant:          1:iPhone15,3:17
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           andy.DeadLineTodo [2089]

Date/Time:           2024-06-08 19:13:53.6259 +0800
Launch Time:         2024-06-08 19:13:53.2839 +0800
OS Version:          iPhone OS 17.5.1 (21F90)
Release Type:        User
Baseband Version:    2.60.02
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000195a2d8c0
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [5556]

Triggered by Thread:  0


Thread 0 name:
Thread 0 Crashed:
0   libswiftCore.dylib            	0x0000000195a2d8c0 _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:144)
1   DeadLineTodo                  	0x0000000100dde700 DeadLineTodoApp.init() + 1140 (DeadLineTodoApp.swift:46)
2   DeadLineTodo                  	0x0000000100ddef30 protocol witness for App.init() in conformance DeadLineTodoApp + 28 (<compiler-generated>:0)
3   SwiftUI                       	0x000000019b2c84c0 static App.main() + 116 (App.swift:114)
4   DeadLineTodo                  	0x0000000100ddeec4 static DeadLineTodoApp.$main() + 40 (<compiler-generated>:0)
5   DeadLineTodo                  	0x0000000100ddef5c main + 12 (DeadLineTodoApp.swift:32)
6   dyld                          	0x00000001ba7d1e4c start + 2240 (dyldMain.cpp:1298)

Thread 1:
0   libsystem_pthread.dylib       	0x00000001f3fa40c4 start_wqthread + 0 (:-1)

Thread 2:
0   libsystem_pthread.dylib       	0x00000001f3fa40c4 start_wqthread + 0 (:-1)


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x8000000100f01ad0   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x00000003019e9bc0
    x4: 0x0000000000000000   x5: 0x000000016f16f3e0   x6: 0x000000000000002e   x7: 0x0000000000000000
    x8: 0x0000000000000100   x9: 0x00000000000000ff  x10: 0x0000000000001b80  x11: 0x00000000f3444870
   x12: 0x00000000000007fb  x13: 0x00000000000007fd  x14: 0x00000000f364506f  x15: 0x000000000000006f
   x16: 0x00000000f3444870  x17: 0x0000000000045000  x18: 0x0000000000000000  x19: 0x0000000100f01dba
   x20: 0x8000000100f01ad0  x21: 0x0000000000000000  x22: 0x000000000000000b  x23: 0x0000000000000022
   x24: 0x000000000000002e  x25: 0x0000000100f01ac0  x26: 0xd000000000000025  x27: 0x0000000000000000
   x28: 0x0000000000000000   fp: 0x000000016f16f5c0   lr: 0x0000000195a2d8c0
    sp: 0x000000016f16f4f0   pc: 0x0000000195a2d8c0 cpsr: 0x60001000
   esr: 0xf2000001 (Breakpoint) brk 1


Binary Images:
        0x100c90000 -         0x100f0ffff DeadLineTodo arm64  <c16650393d4537299a08b798b8227d31> /private/var/containers/Bundle/Application/348CC8D5-05FD-41DF-93A3-C15562EF4AA8/DeadLineTodo.app/DeadLineTodo
        0x101214000 -         0x10121ffff libobjc-trampolines.dylib arm64e  <2e2c05f8377a30899ad91926d284dd03> /private/preboot/Cryptexes/OS/usr/lib/libobjc-trampolines.dylib
        0x1959f4000 -         0x195f43fff libswiftCore.dylib arm64e  <d9ad5cc1ca2c3f0a8091652b0df56d14> /usr/lib/swift/libswiftCore.dylib
        0x19af1c000 -         0x19ccbafff SwiftUI arm64e  <c1325fda9da239d2ab83a338b4d8a884> /System/Library/Frameworks/SwiftUI.framework/SwiftUI
        0x1ba795000 -         0x1ba821ef7 dyld arm64e  <71846eacee653697bf7d790b6a07dcdb> /usr/lib/dyld
        0x1f3fa3000 -         0x1f3fafff3 libsystem_pthread.dylib arm64e  <1196b6c3333d3450818ff3663484b8eb> /usr/lib/system/libsystem_pthread.dylib

EOF

DeadLineTodoApp.swift

import SwiftUI
import SwiftData

typealias TodoData =  TodoDataSchemaV8.TodoData
typealias UserSetting = TodoDataSchemaV8.UserSetting

enum TodoDataMigrationPlan: SchemaMigrationPlan {
    static var schemas: [VersionedSchema.Type] {
        [TodoDataSchemaV1.self, TodoDataSchemaV2.self, TodoDataSchemaV3.self, TodoDataSchemaV4.self, TodoDataSchemaV5.self, TodoDataSchemaV6.self, TodoDataSchemaV7.self, TodoDataSchemaV8.self]
    }
    static var stages: [MigrationStage]{
        [migrationV1toV2, migrationV2toV3, migrationV3toV4, migrationV4toV5, migrationV5toV6, migrationV6toV7, migrationV7toV8]
    }
    static let migrationV1toV2 = MigrationStage.lightweight(fromVersion: TodoDataSchemaV1.self, toVersion: TodoDataSchemaV2.self)
    static let migrationV2toV3 = MigrationStage.lightweight(fromVersion: TodoDataSchemaV2.self, toVersion: TodoDataSchemaV3.self)
    static let migrationV3toV4 = MigrationStage.lightweight(fromVersion: TodoDataSchemaV3.self, toVersion: TodoDataSchemaV4.self)
    static let migrationV4toV5 = MigrationStage.lightweight(fromVersion: TodoDataSchemaV4.self, toVersion: TodoDataSchemaV5.self)
    static let migrationV5toV6 = MigrationStage.lightweight(fromVersion: TodoDataSchemaV5.self, toVersion: TodoDataSchemaV6.self)
    static let migrationV6toV7 = MigrationStage.lightweight(fromVersion: TodoDataSchemaV6.self, toVersion: TodoDataSchemaV7.self)
    static let migrationV7toV8 = MigrationStage.lightweight(fromVersion: TodoDataSchemaV7.self, toVersion: TodoDataSchemaV8.self)
}


@main
struct DeadLineTodoApp: App {
    let container: ModelContainer
    
    @StateObject var store = StoreKitManager()
    
    @State var updated: Bool = false
    
    init() {
        do {
            container = try ModelContainer(
                for: TodoData.self, UserSetting.self,
                migrationPlan: TodoDataMigrationPlan.self)
        } catch {
            print("初始化模型容器时发生错误:\(error)")
            fatalError("Failed to initialize model container.")
        }
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView(updated: $updated)
                .environmentObject(store)
        }
        .modelContainer(container)
    }
}
SwiftData migration error
 
 
Q