您好我要在appstore中更新我的iOS应用程序,此更新包含数据库更改,现在如何通过删除应用程序更新中现有版本的旧数据库来迁移现有核心数据? 我提到了Core Data Migration tutorial
不幸的是没有用。任何帮助都提前得到赞赏
答案 0 :(得分:8)
答案 1 :(得分:2)
在应用自动迁移之前,您是否可能尚未创建新版本的数据库模型?
确保您具有automigrate选项,如下所示:
-(NSPersistentStoreCoordinator *)storeCoordinator {
if (storeCoordinator_ != nil) {
return storeCoordinator_;
}
NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"[dbname].sqlite"]];
NSDictionary* storeOptions = @{NSMigratePersistentStoresAutomaticallyOption : [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption : [NSNumber numberWithBool:YES]};
NSError *error = nil;
storeCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self objectModel]];
if (![storeCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:storeOptions error:&error]) {
// handle error here and remove abort
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return storeCoordinator_;
}
然后离开。