简体   繁体   English

Coredata轻量级迁移失败

[英]Coredata Lightweight Migration Fails

If I add a new model version and then add an attribute to an entity I get a migration failure. 如果添加新的模型版本,然后将属性添加到实体,则会发生迁移失败。 It doesn't matter what the type of the attribute is or whether it is optional or has a default value. 属性的类型是什么,属性是可选的还是具有默认值都无关紧要。 If I just add the new model version but don't add the attribute it works OK. 如果我只是添加新的模型版本,但不添加属性,则可以正常工作。 I have done this sort of thing lots of times over the past 3 years without problems. 在过去的三年中,我已经无数次地做了这种事情。 Both NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption are set to true. NSMigratePersistentStoresAutomaticallyOption和NSInferMappingModelAutomaticallyOption均设置为true。 The error I get is shown below. 我得到的错误如下所示。

2018-02-18 12:28:51.771608+0000 Writing Shed[4105:1886727] [error] error: Illegal attempt to save to a file that was never opened. 2018-02-18 12:28:51.771608 + 0000正在写入Shed [4105:1886727] [错误]错误:非法尝试保存到从未打开过的文件。 "This NSPersistentStoreCoordinator has no persistent stores (schema mismatch or migration failure). It cannot perform a save operation.". “此NSPersistentStoreCoordinator没有永久存储(模式不匹配或迁移失败)。它无法执行保存操作。”。 Last recorded error = Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model." 最后记录的错误=错误域= NSCocoaErrorDomain代码= 134140“持久性存储迁移失败,缺少映射模型。”

Does anyone know what might be wrong? 有谁知道可能出什么问题了?

I've found the problem. 我发现了问题。 I'm developing an app on Mac OS that is already available on IOS. 我正在Mac OS上开发IOS上已可用的应用程序。 They sync CoreData via iCloud. 他们通过iCloud同步CoreData。 At some point while working on the Mac I added some attributes to the model that weren't optional or defaulted. 在Mac上工作时,有时会向模型添加一些非可选或默认的属性。 To cut a long story short this caused problems with an IOS store that predated the changes, so that's when the migration failed (can't migrate to non-optional/non-defaulted attributes). 简而言之,这会导致发生更改之前的IOS存储出现问题,这就是迁移失败的时候(无法迁移到非可选/非默认属性)。 I'm still not sure how I got into this situation because I'm usually very careful with CoreData, but hey stuff happens. 我仍然不确定如何进入这种情况,因为我通常对CoreData非常小心,但是发生了很多事情。 Thanks for the comments which made me look deeper. 感谢您的评论,这使我看起来更加深刻。

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

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