그 후 약간의 처리를 통해 간단한 마이그레이션을 보관하려고합니다. 이미 경량 프로세스를 수행 했으므로 현재 엔티티를 처리하는 데 도움이 필요합니다.CoreData Lightweight Migration + Custom
이전 모델에서 나는 "Car"라는 엔티티를 사용했고 이제 Person has Cars와의 관계가있는 "Person"엔티티를 추가했습니다.
가벼운 이동 후에 기본 사용자 "John"을 추가하고 모든 자동차를 추가해야합니다.
누구에게 아이디어가 있습니까?
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreData.sqlite"];
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
도움 주셔서 감사합니다. 미래에 내 모델의 또 다른 버전을 만들면 어떨까요? 그것을 추적 할 방법이 있습니까? 만약 v2로 업그레이드 할 예정이라면, v3에 업그레이드하면 Vincent를 삽입할까요? –
네, 다른 답변에 설명 된대로 버전에 대해 항상'NSObjectModel'을 쿼리 할 수 있습니다. – Mundi