0
我的遷移有一些問題。 遷移之前,我曾在我的模型2個表:核心數據模型遷移步驟
- 食物:名稱(字符串),類別(字符串),等等...
- CartFood:名稱(字符串),類別(字符串) etc ...
我需要創建一個新的實體「類別」,並將兩個表的類別屬性轉換爲一對多關係。我也想爲Food實體添加屬性並創建其他實體。
的步驟我有如下如下:
1-添加模型版本,並創建新的類別的實體,刪除類別屬性,建立關係,添加新的屬性,等等
2-用相同的代碼
3-創建我的自定義實體遷移策略類(它們是NSEntityMigrationPolicy的子類)創建映射模型
4-禁用輕量級遷移
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// Stop that right now if necessary
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
// Store URL
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"LeSecretDuPoids.sqlite"]];
// Get store
NSError *error = nil;
NSDictionary *options = @{ NSMigratePersistentStoresAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @NO };
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
但是,當我推出新的應用程序,我有以下錯誤,沒有日誌顯示在控制檯:
CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null)
我錯過了什麼嗎?
Regards, Sébastien。
是否可以使用NSEntityMigrationPolicy子類輕量級遷移? – Seb 2015-02-13 09:04:26
如果我忽略這兩個字符串,當創建新的商店時,類別關係將爲空,我將無法獲取舊值:/ – Seb 2015-02-13 09:05:35
不,請閱讀我的答案。你必須親自填充新的關係。但它比使用調試自定義遷移更簡單。 – Mundi 2015-02-13 12:56:53