iphone – cocoa错误134100再次 – (用于打开的模型与用于创建的
我在这里发布了这个问题,但总是,答案是模型已经改变,重置模拟器,删除商店.
我也收到了这个错误,但是,这是一个新的应用程序.我没有添加/更改实体或属性. 我删除了商店,我重置了模拟器,但我得到了相同的结果. 这是商店代码..这个问题还有其他原因吗? - (NSManagedObjectModel *)managedObjectModel { // NSLog(@"%s",__FUNCTION__); if (managedObjectModel_ != nil) { return managedObjectModel_; } NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"Lexicon" ofType:@"momd"]; NSURL *modelURL = [NSURL fileURLWithPath:modelPath]; managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return managedObjectModel_; } /** Returns the persistent store coordinator for the application. If the coordinator doesn't already exist,it is created and the application's store added to it. */ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator_ != nil) { return persistentStoreCoordinator_; } NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"dict.sqlite"]]; NSError *error = nil; persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { NSLog(@"Unresolved error %@,%@",error,[error userInfo]); abort(); } return persistentStoreCoordinator_; } 这是控制台喷出的:
解决方法
事实证明,sqlite DB存储是错误构建的.因此,在这种情况下,消息相当准确.
上面的问题是真的.数据库没有反映模型. 解决方案是让Core Data从模型中创建空数据库,然后让Core Data自行导入数据. 我首先将我的sqlite数据库导出到sql,调用文件db.sql(imaginative!).我只导出数据表和主键表,而不是元数据表.我使用了一个名为SQLiteManager的应用程序.您也可以在命令行执行此操作. 除处理持久存储控制器外,所有代码都是库存. 该代码如下: - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator_ != nil) { return persistentStoreCoordinator_; } NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"db.sql"]; // set up the backing store NSFileManager *fileManager = [NSFileManager defaultManager]; // If the expected store doesn't exist,copy the default store. if (![fileManager fileExistsAtPath:storePath]) { NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"dict" ofType:@"sqlite"]; if (defaultStorePath) { [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL]; } } NSURL *storeURL = [NSURL fileURLWithPath:storePath]; NSError *error = nil; persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { NSLog(@"Unresolved error %@,[error userInfo]); abort(); } return persistentStoreCoordinator_; } 我希望这有帮助..它似乎对我有用.. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |