我正在努力解决核心数据迁移问题。
基本上,我们有 15 个数据模型,到目前为止,我们对 inferMapping 和 autoMigration 选项非常满意:
NSDictionary *lcOptions = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
现在我有一个要重命名的字段,一个要删除的关系和一个要创建的新关系。我选择了映射模型,因为我认为它可以正常工作,但事实并非如此。
基本上,迁移正常,直到它说:
[Migration doing OK apparently]
2013-10-23 18:19:25.561 MyApp[80546:c07] CoreData: sql: SELECT 0, ....
2013-10-23 18:19:25.562 MyApp[80546:c07] CoreData: annotation: sql connection fetch time: 0.0004s
2013-10-23 18:19:25.562 MyApp[80546:c07] CoreData: annotation: total fetch execution time: 0.0008s for 2 rows.
2013-10-23 18:19:25.562 MyApp[80546:1b03] CoreData: annotation: Disconnecting from sqlite database.
2013-10-23 18:19:25.564 MyApp[80546:1303] CoreData: annotation: Disconnecting from sqlite database.
2013-10-23 18:19:25.564 MyApp[80546:c07] CoreData: annotation: (migration) leaving incompletely migrated store on disk after automatic migration failure. (file://localhost/Users/vdesaintpern/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/1B73B767-2BFC-4716-B93B-E9CFA29952A8/Library/Application%20Support/.MyDatabase.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3)
2013-10-23 18:19:25.564 MyApp[80546:c07] CoreData: error: (migration) migration failed with error (null)
2013-10-23 18:19:25.564 MyApp[80546:c07] Unresolved error (null), (null)
->崩溃
我的数据库在库/应用程序支持中,它似乎是完全可读/可写的。
Core Data 中的“剩余”(.MyDatabase.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3)是完全可读的,并且似乎包含了我需要正确迁移的所有数据。
我已经尝试了很多次,重新创建了映射模型,一次又一次地完成了整个过程。没运气。
好吧,老实说,它上周有效,但它不再有效(当我看到它有效时,我检查了我提交的确切修订版)。没有更改 XCode 或我系统中的任何内容。
我在 Mac 上发现了一个有同样问题的人,但不幸的是,该解决方法不适用于 iOS。
任何帮助将不胜感激。