0
我每次屬性添加到我的CoreData實體之一,並運行應用程序,我得到了CoreData一個例外,一切(我創建的所有對象)將被刪除。爲什麼在更改實體的屬性時我的CoreData信息被刪除?
在我的AppDelegate:
- (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";
}
我似乎無法找到我的問題。修改實體時是否總是需要創建新的模型版本?我認爲它會自動遷移?