繁体   English   中英

尝试通过轻量级迁移来更新我的DBModel,但没有任何反应

[英]Trying to update my DBModel with lightweight migration but nothing happens

因此,我的数据库模型中的类别已更新(在出现4之前,现在是7),我也想用新对象更新核心数据。

我试图应用这个: https : //developer.apple.com/documentation/coredata/using_lightweight_migration

    lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
    // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
    // Create the coordinator and store
    let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
    let url = self.applicationDocumentsDirectory.appendingPathComponent("x.sqlite")
    let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
    var failureReason = "There was an error creating or loading the application's saved data."
    do {
        try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: options)
    } catch {
        // Report any error we got.}

但是我的数据是相同的...不会使用新类别进行更新。 有什么帮助吗? 谢谢.. PS:我应该制作一个新模型并将旧模型映射到新模型中吗? 在此处输入图片说明

您只是忘记添加另一个模型,如果只有一个模型,则无法在模型之间进行迁移,因此只需选择xcdatamodel,然后打开Editor-> add Model Version然后转到File Inspector并选择新的xcdatamodel作为当前模型,则得到结果。 祝你好运亲爱的朋友

您需要创建CORE DATABASE的数据库模型版本。 您可以按照创建数据库版本控制的步骤进行操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM