iPhone Core Data轻量级迁移Cocoa错误134130:找不到源存储的模型 [英] iPhone Core Data Lightweight Migration Cocoa error 134130: Can't find model for source store
问题描述
人
轻量级迁移在这一行上100%的时间失败:
Lightweight migration is failing for me 100% of the time on this line:
[persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]
出现错误:
Error: Error Domain=NSCocoaErrorDomain Code=134130 UserInfo=0x4fbff20 "Operation could not be completed. (Cocoa error 134130.)"
"Can't find model for source store";
这是我的托管对象上下文,模型和持久存储:
Here is my managed object context, model, and persistent store:
- (NSManagedObjectContext *) managedObjectContext {
if (managedObjectContext != nil) {
return managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator: coordinator];
}
return managedObjectContext;
}
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
return managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Locations.sqlite"]];
NSError *error;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
// Allow inferred migration from the original version of the application.
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(@"Error: %@",error);
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
我在我的项目中有两个版本的模型:版本4和版本5.如果我将我的版本4设置为默认值,它工作正常。如果我选择设计 - >数据模型 - >添加模型版本(如此帖子),进行更改,设计 - >数据模型 - >设置当前版本,构建和运行,它将失败,前面提到的无法找到源存储模型错误。将模型设置回版本4,没有问题,addPersistentStoreWithType。或者,如果我添加模型版本并且不做任何更改,只需从版本4到5,而不添加任何新字段,没有问题。如果我然后尝试从5到6,上述错误。
I have two versions of my model in my project: a version 4 and a version 5. If I set my version 4 as default, it works fine. If I select "Design -> Data Model -> Add Model Version" (as described by this post), make a change, Design -> Data Model -> Set Current Version, build and run, it will fail with the aforementioned "Can't find model for source store" error. Set model back to version 4, no problems, addPersistentStoreWithType. Alternatively, if I add model version and make no changes, simply go from version 4 to 5 without adding any new fields, no problems. If I then try to go from 5 to 6, the aforementioned error.
这个代码在模拟器和手机上都失败了。我读了几个处方,呼吁删除和重新安装应用程序,这是工作的模拟器和电话,但恐怕,当我发布这个真正的用户,它会打破我的安装基地,因为他们将无法删除和重新安装 - App Store会自动升级。
This code is failing on both Simulator and Phone. I read several prescriptions calling for deleting and reinstalling the app, which does work for both Simulator and Phone, but I am afraid that when I release this to real users it will break my installed base since they won't be able to delete and reinstall - App Store will auto-upgrade them.
此代码在过去的版本中工作,没有任何更改 - 因此我能够使其一直到版本4.我最近升级到XCode 3.2.3构建iOS4,这可能与这有关。
This code worked in releases past with no changes on my part - hence my ability to make it all the way up to version 4. I recently upgraded to XCode 3.2.3 building for iOS4, which may have something to do with this.
其他人是否突然有这个问题,就像我一样?有人设法工作过去吗?感谢。
Is anyone else having this issue all of a sudden now like I am? Has anyone managed to work past it? Thanks.
PS - 对于在此页面上绊脚的Google员工,以下是您可能会考虑阅读的所有相关页面。很遗憾,这些问题都无法解决我的问题。
PS - For Googlers who stumble on this page, here are all the relevant pages you might consider reading, below. Unfortunately none of these solved my issue.
- http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html
- http://stackoverflow.com/questions/2925918/iphone -core-data-lightweight-migration-error-reason-cant-find-model-for-sour
- iPhone Core Data自动轻量级迁移
- http://www.iphonedevsdk.com/forum/iphone-sdk-development/38545 -coredata-migration-issues.html
- Implementation of "Automatic Lightweight Migration" for Core Data (iPhone)
- http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html
- http://stackoverflow.com/questions/2925918/iphone-core-data-lightweight-migration-error-reason-cant-find-model-for-sour
- iPhone Core Data "Automatic Lightweight Migration"
- http://www.iphonedevsdk.com/forum/iphone-sdk-development/38545-coredata-migration-issues.html
UPDATE
虽然这不是一个真正的修复,它避免了客户端崩溃的情况:只需删除数据库文件:
While this is not a real fix, it does avoid the scenario of a crashing client: simply delete the database file:
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
// Delete file
if ([[NSFileManager defaultManager] fileExistsAtPath:storeUrl.path]) {
if (![[NSFileManager defaultManager] removeItemAtPath:storeUrl.path error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error])
{
// Handle the error.
NSLog(@"Error: %@",error);
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
UPDATE 2
UPDATE 2
下面是当我检查VersionInfo.plist时会发生什么:
Here is what happens when I inspect VersionInfo.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSManagedObjectModel_CurrentVersionName</key>
<string>Profile 5</string>
<key>NSManagedObjectModel_VersionHashes</key>
<dict>
<key>Profile</key>
<dict>
<key>Profile</key>
<data>
ZIICGgMBreuldkPXgXUhJwKamgwJzESM5FRTOUskomw=
</data>
</dict>
<key>Profile 2</key>
<dict>
<key>Profile</key>
<data>
tEB7HrETWOSUuoeDonJKLXzsxixv8ALHOoASQDUIZMA=
</data>
</dict>
<key>Profile 3</key>
<dict>
<key>Profile</key>
<data>
qyXOJyKkfQ8hdt9gcdFs7SxKmZ1JYrsXvKbtFQTTna8=
</data>
</dict>
<key>Profile 4</key>
<dict>
<key>Profile</key>
<data>
lyWDJJ0kGcs/pUOModd3Q1ymDvdRiNXui4NCpLxDFSw=
</data>
</dict>
<key>Profile 5</key>
<dict>
<key>Profile</key>
<data>
V4PyRK1ezj3xK1QFRCTVzGOqyJhEb7FRMzglrTsP0cI=
</data>
</dict>
</dict>
</dict>
</plist>
这是我写的检查我的模型的代码(注意,我不得不出去,因为这是VersionInfo.plist文件中的)
Here is the code that I wrote to inspect my model (note I had to go out and add a base64 encoder, since that is what is in the VersionInfo.plist file)
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSDictionary *storeMeta = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:nil URL:storeUrl error:&error];
NSLog(@"%@",storeMeta);
id someObj = [[storeMeta objectForKey:@"NSStoreModelVersionHashes"] objectForKey:@"Profile"];
NSLog(@"%@",someObj);
NSLog(@"%@",[NSString base64StringFromData:someObj length:[someObj length]]);
这里是调试输出:
{
NSPersistenceFrameworkVersion = 310;
NSStoreModelVersionHashes = {
Profile = <97258324 9d2419cb 3fa5438c a1d77743 5ca60ef7 5188d5ee 8b8342a4 bc43152c>;
SerializedMessage = <4530863c d943479a edfb4dfb 5059c28d d6137dc4 d1153d36 ed52be49 11074f13>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
);
NSStoreType = SQLite;
NSStoreUUID = "823FD306-696F-4A0F-8311-2792825DC66E";
"_NSAutoVacuumLevel" = 2;
}
<97258324 9d2419cb 3fa5438c a1d77743 5ca60ef7 5188d5ee 8b8342a4 bc43152c>
lyWDJJ0kGcs/pUOModd3Q1ymDvdRiNXui4NCpLxDFSw=
正如你所看到的, '匹配VersionInfo.plist中的Profile 4 ...因此我看不到为什么它应该失败的原因。任何其他想法?
As you can see, that last line that starts with 'ly' matches Profile 4 in VersionInfo.plist...hence I see no reason why it should be failing. Any other ideas?
推荐答案
人们,
为了记录,我停止使用核心数据。我的代码是复杂的,根据上面的问题,不可靠。我现在直接使用SQLLite和我更快乐。我不能推荐在任何情况下使用Core Data。
For the record, I ceased use of core data completely. My code was complicated and, per the issues above, unreliable. I use SQLLite directly now and am WAY happier. I cannot recommend using Core Data in any scenario.
这篇关于iPhone Core Data轻量级迁移Cocoa错误134130:找不到源存储的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!