{"id":1479,"date":"2012-06-16T21:45:40","date_gmt":"2012-06-17T01:45:40","guid":{"rendered":"http:\/\/cd34.com\/blog\/?p=1479"},"modified":"2012-06-16T21:45:40","modified_gmt":"2012-06-17T01:45:40","slug":"the-model-used-to-open-the-store-is-incompatible-with-the-one-used-to-create-the-store","status":"publish","type":"post","link":"https:\/\/cd34.com\/blog\/iphone\/the-model-used-to-open-the-store-is-incompatible-with-the-one-used-to-create-the-store\/","title":{"rendered":"The model used to open the store is incompatible with the one used to create the store"},"content":{"rendered":"<p>I ran into this while doing some development for SnapReplay, and, I knew that this would be a problem. Regrettably, the favorite solution is to delete the app or erase the virtual instance and start fresh, but, what causes this?<\/p>\n<p>When your application first starts and you have a schema defined for SQLite, a database file is created and versioned. When you later make changes to the table schemas or add a new table, the version number is updated to allow migration. People that have downloaded your app are not going to want to uninstall the app and reinstall it.<\/p>\n<p>So, we&#8217;ve made changes to our table schema, added or modified a table or whatever. Now, we need to go to our list of files, right click, New File&#8230; IOS Core Data, NSManagedObject subclass, hit next, select the Data Model for your project, select the entities. If you have only added a new table, select it, if you have modified tables, select them as well. Hit next, then, create the files.<\/p>\n<p>Now, you have a few options. If your changes are slight, you can use the <a href=\"https:\/\/developer.apple.com\/library\/ios\/#documentation\/Cocoa\/Conceptual\/CoreDataVersioning\/Articles\/vmLightweightMigration.html#\/\/apple_ref\/doc\/uid\/TP40004399-CH4-SW1\">lightweight migration<\/a> (in your App Delegate file):<\/p>\n<pre>\r\n- (NSPersistentStoreCoordinator *)persistentStoreCoordinator\r\n{\r\n    if (__persistentStoreCoordinator != nil)\r\n    {\r\n        return __persistentStoreCoordinator;\r\n    }\r\n    \r\n    NSError *error = nil;\r\n    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@\"SnapReplay.sqlite\"];\r\n    \r\n    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];\r\n    \r\n    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];\r\n<\/pre>\n<p>For a more complete discussion regarding more complicated data migrations, you can refer to Apple&#8217;s <a href=\"https:\/\/developer.apple.com\/library\/ios\/#documentation\/Cocoa\/Conceptual\/CoreDataVersioning\/Articles\/Introduction.html\">Core Data Model Versioning and Data Migration<\/a> guide.<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/iphone\/the-model-used-to-open-the-store-is-incompatible-with-the-one-used-to-create-the-store\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I ran into this while doing some development for SnapReplay, and, I knew that this would be a problem. Regrettably, the favorite solution is to delete the app or erase the virtual instance and start fresh, but, what causes this? When your application first starts and you have a schema defined for SQLite, a database [&hellip;]<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/iphone\/the-model-used-to-open-the-store-is-incompatible-with-the-one-used-to-create-the-store\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[272,273,274],"class_list":["post-1479","post","type-post","status-publish","format-standard","hentry","category-iphone","tag-app","tag-core-data","tag-versioning"],"_links":{"self":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/comments?post=1479"}],"version-history":[{"count":2,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1479\/revisions"}],"predecessor-version":[{"id":1481,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1479\/revisions\/1481"}],"wp:attachment":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/media?parent=1479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/categories?post=1479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/tags?post=1479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}