내 CoreData 엔티티 중 하나에 속성을 추가하고 앱을 실행할 때마다 예외가 발생하고 CoreData의 모든 항목 (내가 만든 모든 객체)이 삭제됩니다. 내 AppDelegate에에서엔티티의 속성을 변경할 때 CoreData 정보가 지워지는 이유는 무엇입니까?
:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator == nil) {
NSURL *storeURL = [NSURL fileURLWithPath:[self dataStorePath]]
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];
NSError *error;
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error])
{
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
NSLog(@"Deleted old database %@, %@", error, [error userInfo]);
[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{NSMigratePersistentStoresAutomaticallyOption:@YES} error:&error];
abort();
}
}
return _persistentStoreCoordinator;
}
- (NSManagedObjectContext *)managedObjectContext
{
if (_managedObjectContext == nil) {
NSPersistentStoreCoordinator *coordinator = self.persistentStoreCoordinator;
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
}
}
return _managedObjectContext;
}
오류가 나는 얻을 :
2014-02-23 01:37:08.702 SoundQuiz[8063:70b] Deleted old database Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0xc8796f0 {URL=file:///Users/Eli/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/7041F45C-D3B2-4B9D-94A0-F5B68482D065/Documents/DataStore.sqlite, metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
CategoryLevel = <f9824409 52866ec4 6a02251e d7b32d21 430cedd7 2b83ce04 1997e50c 2e0137d6>;
GameCategory = <d65d9779 80986a4b da767cae b208d733 7944cebf c146e242 e7c9f0ff fc06eb31>;
LevelSound = <2b23da4d ef82c20d 68a5de45 efb7b2f0 26621867 68904b04 04144acb 44fd43fd>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "A28E8265-2D65-439E-9634-55482C4ED9F0";
"_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}, {
URL = "file:///Users/Eli/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/7041F45C-D3B2-4B9D-94A0-F5B68482D065/Documents/DataStore.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes = {
CategoryLevel = <f9824409 52866ec4 6a02251e d7b32d21 430cedd7 2b83ce04 1997e50c 2e0137d6>;
GameCategory = <d65d9779 80986a4b da767cae b208d733 7944cebf c146e242 e7c9f0ff fc06eb31>;
LevelSound = <2b23da4d ef82c20d 68a5de45 efb7b2f0 26621867 68904b04 04144acb 44fd43fd>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "A28E8265-2D65-439E-9634-55482C4ED9F0";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
나는 내 문제를 찾을 수 없습니다. 엔터티를 수정할 때 항상 새로운 모델 버전을 만들어야합니까? 자동으로 마이그레이션 할 것이라고 생각 했습니까?