我想用2个CoreData数据库进行迁移。我看过apple developer document。
对于第一个数据库,我向新版本的数据库添加了一些属性(字符串,整数和日期属性)。按照所有步骤,我已成功完成第一个迁移。
但是第二个数据库,我还为新版本的数据库添加了属性(字符串,整数,日期,可转换和二进制数据属性)。并且遵循所有步骤(与第一个数据库一样),系统返回错误(134130)。
以下是代码:
if (persistentStoreCoordinator_) {
PMReleaseSafely(persistentStoreCoordinator_);
}
// Notify
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:GCalWillMigrationNotification object:self];
//
NSString *sourceStoreType = NSSQLiteStoreType;
NSString *dataStorePath = [PMUtility dataStorePathForName:GCalDBWarehousePersistentStoreName];
NSURL *storeURL = [NSURL fileURLWithPath:dataStorePath];
BOOL storeExists = [[NSFileManager defaultManager] fileExistsAtPath:dataStorePath];
//
NSError *error = nil;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];
[persistentStoreCoordinator_ addPersistentStoreWithType:sourceStoreType
configuration:nil
URL:storeURL
options:options
error:&error];
if (error != nil) {
abort();
}
错误不是nil,下面是log:
Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn\u2019t be completed. (Cocoa error 134130.)" UserInfo=0x856f790 {URL=file://localhost/Users/greensun/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/D10712DE-D9FE-411A-8182-C4F58C60EC6D/Library/Application%20Support/XXX/XXX.sqlite, metadata={type = immutable dict, count = 7, entries => 2 : {contents = "NSStoreModelVersionIdentifiers"} = {type = immutable, count = 1, values = ( 0 : {contents = ""} )} 4 : {contents = "NSPersistenceFrameworkVersion"} = {value = +386, type = kCFNumberSInt64Type} 6 : {contents = "NSStoreModelVersionHashes"} = {type = immutable dict, count = 2, entries => 0 : {contents = "XXX"} = {length = 32, capacity = 32, bytes = 0xfdae355f55c13fbd0344415fea26c8bb ... 4c1721aadd4122aa} 1 : {contents = "XXX"} = {length = 32, capacity = 32, bytes = 0x7676888f0d7eaff4d1f844343028ce02 ... 040af6cbe8c5fd01} } 7 : {contents = "NSStoreUUID"} = {contents = "51678BAC-CCFB-4D00-AF5C-8FA1BEDA6440"} 8 : {contents = "NSStoreType"} = {contents = "SQLite"} 9 : {contents = "_NSAutoVacuumLevel"} = {contents = "2"} 10 : {contents = "NSStoreModelVersionHashesVersion"} = {value = +3, type = kCFNumberSInt32Type} }, reason=Can't find model for source store}
我尝试了很多解决方案,但它不起作用。我只是为2个新版本数据库添加了更多属性,并成功迁移了一次。
答案 0 :(得分:1)
这是iOS5中Apple框架中的一个错误。我假设您是Apple iOS开发人员计划的成员,因此您可以在Apple Developer Forums中阅读此内容。
简而言之,这意味着如果您拥有多个模型,例如您使用两个持久性存储(但不仅如此),则在某些情况下您无法添加一个数据模型的新版本,而其他模型仍保留在其中当前版本。
它已提交给Apple并标记为重复。我不知道iOS6中是否已修复此问题。