简体   繁体   English

Restkit 0.20 CoreData错误“找不到源存储的模型”

[英]Restkit 0.20 CoreData error “Can't find model for source store”

I am trying to configure RestKit with CoreData. 我正在尝试使用CoreData配置RestKit。 I get and error with "Can't find model for source store". 我收到并出现“找不到源存储的模型”错误。 I was using the configurations from the Restkit RKTwitterCoreData example. 我使用的是Restkit RKTwitterCoreData示例中的配置。 I found some similar posts on stack overflow where people say to delete the database but I don't know how to do this, am running on my phone, not the simulator. 我在堆栈溢出中发现了一些类似的帖子,其中有人说要删除数据库,但我不知道如何做到这一点,它是在手机上而不是模拟器上运行的。 I also tried to do a Product:Clean but same error. 我也尝试做一个Product:Clean但同样的错误。

 2014-05-18 12:29:16.489 What my life could be[7006:60b] I restkit:RKLog.m:34 RestKit logging initialized...
2014-05-18 12:29:17.259 What my life could be[7006:60b] *** Assertion failure in -[AppDelegate application:didFinishLaunchingWithOptions:], /Users/Pro/Desktop/ios app/What my life could be/What my life could be/AppDelegate.m:161
2014-05-18 12:29:17.262 What my life could be[7006:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to add persistent store with error: Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x15d7fc40 {URL=file:///var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite, metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes =     {
    ActivityEntity = <fdd7d538 648131cf 2fe3b684 bd55169e 85a7cee4 cbec3080 94202e4c 26b97889>;
    PriorityEntity = <74cd93d0 00ade70c ef4d0ea3 f177762d 7d342720 7aba6945 d83ee02d 96a2135c>;
    UserDataEntity = <2ffd8aec e7c1dacc 23e14fdd 400b60c0 5a1cd9a8 07fe6138 4d0e5a30 8e0c6e28>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers =     (
    ""
);
NSStoreType = SQLite;
NSStoreUUID = "B1BC3FFF-F727-49E4-A44F-5C5216C58226";
"_NSAutoVacuumLevel" = 2;}, reason=Can't find model for source store}'
*** First throw call stack:(0x2ec07e83 0x38f646c7 0x2ec07d55 0x2f5b00af 0xf37bb 0x313fcaad 0x313fc4f3 0x313f6b41 0x31391a07 0x31390cfd 0x313f6321 0x3387676d 0x33876357 0x2ebd2777 0x2ebd2713 0x2ebd0edf 0x2eb3b471 0x2eb3b253 0x313f55c3 0x313f0845 0xf3bc5 0x3945dab7)
libc++abi.dylib: terminating with uncaught exception of type NSException(lldb) 

The part of code to config the store. 用于配置商店的代码部分。 I deleted the CoreData template default code, got error both ways. 我删除了CoreData模板默认代码,双向都出错。 Note: I am not sure how the "importer importObjectsFromItemAtPath:...." works. 注意:我不确定“ importer importObjectsFromItemAtPath:....”的工作方式。

#ifdef RESTKIT_GENERATE_SEED_DB
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelInfo);
RKLogConfigureByName("RestKit/CoreData", RKLogLevelTrace);

NSError *error = nil;
BOOL success = RKEnsureDirectoryExistsAtPath(RKApplicationDataDirectory(), &error);
if (! success) {
    RKLogError(@"Failed to create Application Data Directory at path '%@': %@", RKApplicationDataDirectory(), error);
}
NSString *seedStorePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"JustDid.sqlite"];
RKManagedObjectImporter *importer = [[RKManagedObjectImporter alloc] initWithManagedObjectModel:managedObjectModel storePath:seedStorePath];
[importer importObjectsFromItemAtPath:[[NSBundle mainBundle] pathForResource:@"activities" ofType:@"json"]
                          withMapping:activityMapping
                              keyPath:@"activity"
                                error:&error];
[importer importObjectsFromItemAtPath:[[NSBundle mainBundle] pathForResource:@"users" ofType:@"json"]
                          withMapping:userMapping
                              keyPath:@"user"
                                error:&error];
BOOL success = [importer finishImporting:&error];
if (success) {
    [importer logSeedingInfo];
} else {
    RKLogError(@"Failed to finish import and save seed database due to error: %@", error);
}

// Clear out the root view controller
[self.window setRootViewController:[UIViewController new]];
#else
/**
 Complete Core Data stack initialization
 */
[managedObjectStore createPersistentStoreCoordinator];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"JustD.sqlite"];
NSString *seedPath = [[NSBundle mainBundle] pathForResource:@"RKSeedDatabase" ofType:@"sqlite"];
NSError *error;
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:seedPath withConfiguration:nil options:nil error:&error];
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);

// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];

// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
#endif

It looks like you have changed the version of your core data model and not asked core data to try to migrate automatically or provided a migration explicitly. 看起来您已经更改了核心数据模型的版本,并且没有要求核心数据尝试自动迁移或显式提供了迁移。 So, as core data loads it detects the version mismatch and aborts. 因此,在加载核心数据时,它会检测版本不匹配并中止。

Initially, delete the app from your device and reinstall and everything should work again. 最初,请从您的设备中删除该应用,然后重新安装,然后一切都会恢复正常。 You would need to do this each time you change the data model. 每次更改数据模型时,都需要执行此操作。

Obviously it isn't a good idea to go to the App Store like that so you should research auto migration and it's constraints and (if required) explicit migration. 显然,那样去App Store不是一个好主意,因此您应该研究自动迁移及其约束和(如果需要)显式迁移。

To delete the database, just remove the sqlite file which should be at the address /var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite considering you logs 要删除数据库,只需删除sqlite文件即可,考虑到您的日志记录,该文件应位于/var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite

In a console: rm /var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite 在控制台中:rm /var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite

Have you ensured your seed database is added to the Build Phase : Copy Bundle Resources? 您是否已确保将种子数据库添加到构建阶段:复制捆绑资源?

I've just had the same problem for hours, and in the end it was as simple as that. 我只是在几个小时内遇到了同样的问题,最后就这么简单。 Even though looking in the simulator-deployed app package, the seed sqlit file was there, but for some reason the managedObjectStore couldn't find it, but returned the “Can't find model for source store” error rather than, "Cannot find the seed data file" which would have been more helpful! 即使在模拟器部署的应用程序包中查找,种子sqlit文件也在那里,但是由于某种原因,managedObjectStore找不到它,而是返回“找不到源存储的模型”错误,而不是“找不到”种子数据文件”,这会更有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM