O'Reilly Head First iPhone Development by Dan Pilone & Tracey Pilone (2010 version)
Chapter 7 tab bars and core data: Enterprise/Bounty Hunter apps
Page 359:
Copy the database to the correct place and delete the empty database that Core Data created earlier.

Solution: Troubleshooting core data issues with Head First iPhone Development Chapter 7 Fugitive app
error reason = "The model used to open the store is incompatible with the one used to create the store";

This page documents how I fixed my Fugitive app (p. 359) - it might help you. I'm using XCode 3.2 Beta and named my app differently; either could have caused issues.



p. 359: applicationDidFinishLaunching code should go in this function: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
p. 359: Find your simulator document directory so you can delete it per instructions so your code will try to create it. NSLog(@"%@", [self applicationDocumentsDirectory]);
Run it. If it works, great. Mine didn't.
Verify core data setup: My entity is set up correctly. All my properties are set up correctly, named correctly, in the same order (verified from pages 334-336).
Error: 2010-02-12 11:08:48.289 7BountyHunter[1220:207] Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 UserInfo=0x520b5b0 "Operation could not be completed. (Cocoa error 134100.)", { metadata = { NSPersistenceFrameworkVersion = 248; NSStoreModelVersionHashes = { Fugitive = ; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( ); NSStoreType = SQLite; NSStoreUUID = "E711F65F-3C5A-4889-872B-6541E4B2863A"; "_NSAutoVacuumLevel" = 2; }; reason = "The model used to open the store is incompatible with the one used to create the store"; } This came from me naming my project differently or from me using a different/beta version of XCode.
Delete the simulator sqlite database. Comment out the code for creating a new one. Run again to generate a compatible one. Then compare them. See below.
THEIRS: tford:~> sqlite3 ~/XCodeProjects/_HeadStart/7BountyHunter/iBountyHunter.sqlite SQLite version 3.6.12 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .dump BEGIN TRANSACTION; CREATE TABLE ZFUGITIVE ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZFUGITIVEID INTEGER, ZBOUNTY DECIMAL, ZDESC VARCHAR, ZNAME VARCHAR ); INSERT INTO "ZFUGITIVE" VALUES(1,1,1,99064,1300,'Parole violator','David Adams'); INSERT INTO "ZFUGITIVE" VALUES(2,1,1,6077,56000,'Racketeering','Tracey Martin'); INSERT INTO "ZFUGITIVE" VALUES(3,1,1,56894,96000,'Embezzlement','Joe Daniels'); INSERT INTO "ZFUGITIVE" VALUES(4,1,1,12106,12000,'DUI','Mike Thayer'); INSERT INTO "ZFUGITIVE" VALUES(5,1,1,64235,25000,'Car Theft','Jim Smiley'); INSERT INTO "ZFUGITIVE" VALUES(6,1,1,56659,5000,'Petty theft','George Palin'); INSERT INTO "ZFUGITIVE" VALUES(7,1,1,98122,65000,'Kidnapping','Sarah Carr'); INSERT INTO "ZFUGITIVE" VALUES(8,1,1,45590,10000,'Missing person','Julie Gorman'); INSERT INTO "ZFUGITIVE" VALUES(9,1,1,56815,2300,'DUI after a bar fight he lost.','Vincent Grey'); INSERT INTO "ZFUGITIVE" VALUES(10,1,1,23594,32000,'Mean left hook, wanted for drug running.','Nick Forsee'); INSERT INTO "ZFUGITIVE" VALUES(11,1,1,89716,500,'Hunting license violation.','Hunter Sweeney'); INSERT INTO "ZFUGITIVE" VALUES(12,1,1,12359,56500,'Antisocial and tends to hide. Wanted for embezzlement.','Jim McCarthy'); INSERT INTO "ZFUGITIVE" VALUES(13,1,1,96986,22000,'Followed his dream of car theft.','Michael Merkins'); INSERT INTO "ZFUGITIVE" VALUES(14,1,1,12856,1200,'Escaped from an asylum.','Stanley Fisher'); INSERT INTO "ZFUGITIVE" VALUES(15,1,1,17887,22000,'Car theft and drug possession.','Henry Lewis'); INSERT INTO "ZFUGITIVE" VALUES(16,1,1,25961,1200,'Skipped out on college loans.','Jackson Jones'); INSERT INTO "ZFUGITIVE" VALUES(17,1,1,35805,67000,'Assault, and theft of a pet dog.','Fiona Westin'); INSERT INTO "ZFUGITIVE" VALUES(18,1,1,34571,500,'Running a mailbox baseball ring.','Mike Smithson'); INSERT INTO "ZFUGITIVE" VALUES(19,1,1,45982,45000,'Shop lifting jewelry.','Peggy Ford'); INSERT INTO "ZFUGITIVE" VALUES(20,1,1,12542,23000,'Illegal gambling operation.','Linda Lewis'); INSERT INTO "ZFUGITIVE" VALUES(21,1,1,22365,1200,'Illegal gopher hunging.','Randy Whitmore'); INSERT INTO "ZFUGITIVE" VALUES(22,1,1,34981,250,'Neighborhood fight over landscaping.','Kate Raines'); INSERT INTO "ZFUGITIVE" VALUES(23,1,1,74827,12000,'Lost a bar fight, badly.','Ameilia Bones'); INSERT INTO "ZFUGITIVE" VALUES(24,1,1,34523,45000,'Ran an illegal immigration ring.','Sam Romero'); INSERT INTO "ZFUGITIVE" VALUES(25,1,1,23409,55000,'Bomber for hire.','Jennifer Mai'); INSERT INTO "ZFUGITIVE" VALUES(26,1,1,9234,75000,'Illegal black ops coordinator.','Selina Horatio'); INSERT INTO "ZFUGITIVE" VALUES(27,1,1,87345,25000,'Assault, battery, and running away.','Nicky Wolf'); INSERT INTO "ZFUGITIVE" VALUES(28,1,1,44976,5800,'Bouncer for hire. ','Rudolph Granida'); INSERT INTO "ZFUGITIVE" VALUES(29,1,1,99856,89000,'Ran illegal investing ring. ','Ralph Gustav'); INSERT INTO "ZFUGITIVE" VALUES(30,1,1,32486,6700,'Dogfighting. Toy dogs.','N. Winner'); INSERT INTO "ZFUGITIVE" VALUES(31,1,1,23454,23000,'Stealing cool names from other industries.','Emmanuel Uttenburg '); INSERT INTO "ZFUGITIVE" VALUES(32,1,1,9009,89000,'Tried to dump a guy in the river. Guy got away.','Samantha Fox'); INSERT INTO "ZFUGITIVE" VALUES(33,1,1,74624,2300,'Lost his boss'' dog. Boss was police chief.','John Irahia'); INSERT INTO "ZFUGITIVE" VALUES(34,1,1,84643,5600,'Purse snatcher.','I. Stol eit'); CREATE TABLE Z_PRIMARYKEY (Z_ENT INTEGER PRIMARY KEY, Z_NAME VARCHAR, Z_SUPER INTEGER, Z_MAX INTEGER); INSERT INTO "Z_PRIMARYKEY" VALUES(1,'Fugitive',0,34); CREATE TABLE Z_METADATA (Z_VERSION INTEGER PRIMARY KEY, Z_UUID VARCHAR(255), Z_PLIST BLOB); INSERT INTO "Z_METADATA" VALUES(1,'E711F65F-3C5A-4889-872B-6541E4B2863A',X'62706C6973743030D60102030405060708090A0B0E5F10204E5353746F7 2654D6F64656C56657273696F6E48617368657356657273696F6E5F101E4E5353746F72654D6F64656C56657273696F6E4964656E746966696572735B4E5353746F726 5547970655F101D4E5350657273697374656E63654672616D65776F726B56657273696F6E5F10194E5353746F72654D6F64656C56657273696F6E4861736865735F101 25F4E534175746F56616375756D4C6576656C1003A05653514C69746510F8D10C0D5846756769746976654F1020E33370B6E7CA3101F91D25951E8BFE013E7FB4DE6EF 2A31D9E50237BB313D3905132081538596585A1B6B8B9C0C2C5CEF10000000000000101000000000000000F000000000000000000000000000000F3'); COMMIT; sqlite> .exit
Note: this path came from the NSLog(@"%@", [self applicationDocumentsDirectory]); MINE: tford:~> sqlite3 /Users/tford/Library/Application Support/iPhone Simulator/3.2/Applications/C50BD46B-5B68-42B8-9646-A91471988418/Documents/iBountyHunter.sqlite SQLite version 3.6.12 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .dump BEGIN TRANSACTION; CREATE TABLE ZFUGITIVE ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZFUTITIVEID INTEGER, ZBOUNTY DECIMAL, ZDESC VARCHAR, ZNAME VARCHAR ); CREATE TABLE Z_PRIMARYKEY (Z_ENT INTEGER PRIMARY KEY, Z_NAME VARCHAR, Z_SUPER INTEGER, Z_MAX INTEGER); INSERT INTO "Z_PRIMARYKEY" VALUES(1,'Fugitive',0,0); CREATE TABLE Z_METADATA (Z_VERSION INTEGER PRIMARY KEY, Z_UUID VARCHAR(255), Z_PLIST BLOB); INSERT INTO "Z_METADATA" VALUES(1,'C945F467-6E9C-41F0-A4A9-D52873C4A780',X'62706C6973743030D50102030405060708090A5F101E4E5353746F72654 D6F64656C56657273696F6E4964656E746966696572735B4E5353746F7265547970655F101D4E5350657273697374656E63654672616D65776F726B56657273696F6E5 F10204E5353746F72654D6F64656C56657273696F6E48617368657356657273696F6E5F10194E5353746F72654D6F64656C56657273696F6E486173686573A05653514 C6974651101331003D10B0C5846756769746976654F102017B2EF9F16F877573E3C9CA8FF3C6E4F536F67658054DEE07005B5D5C53BC74D0813344060839FA0A7AAACA FB80000000000000101000000000000000D000000000000000000000000000000DB'); COMMIT; sqlite> .exit tford:~>
Compare the main table Creates to make sure they are the same (if they are different, you need to rebuild - see book): THEIRS: CREATE TABLE ZFUGITIVE ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZFUGITIVEID INTEGER, ZBOUNTY DECIMAL, ZDESC VARCHAR, ZNAME VARCHAR ); MINE: CREATE TABLE ZFUGITIVE ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZFUTITIVEID INTEGER, ZBOUNTY DECIMAL, ZDESC VARCHAR, ZNAME VARCHAR );
Compare the other 2 tables and data: THEIRS: CREATE TABLE Z_PRIMARYKEY (Z_ENT INTEGER PRIMARY KEY, Z_NAME VARCHAR, Z_SUPER INTEGER, Z_MAX INTEGER); INSERT INTO "Z_PRIMARYKEY" VALUES(1,'Fugitive',0,34); CREATE TABLE Z_METADATA (Z_VERSION INTEGER PRIMARY KEY, Z_UUID VARCHAR(255), Z_PLIST BLOB); INSERT INTO "Z_METADATA" VALUES(1,'E711F65F-3C5A-4889-872B-6541E4B2863A',X'62706C6973743030D60102030405060708090A0B0E5F10204E5353746F7 2654D6F64656C56657273696F6E48617368657356657273696F6E5F101E4E5353746F72654D6F64656C56657273696F6E4964656E746966696572735B4E5353746F726 5547970655F101D4E5350657273697374656E63654672616D65776F726B56657273696F6E5F10194E5353746F72654D6F64656C56657273696F6E4861736865735F101 25F4E534175746F56616375756D4C6576656C1003A05653514C69746510F8D10C0D5846756769746976654F1020E33370B6E7CA3101F91D25951E8BFE013E7FB4DE6EF 2A31D9E50237BB313D3905132081538596585A1B6B8B9C0C2C5CEF10000000000000101000000000000000F000000000000000000000000000000F3'); MINE: CREATE TABLE Z_PRIMARYKEY (Z_ENT INTEGER PRIMARY KEY, Z_NAME VARCHAR, Z_SUPER INTEGER, Z_MAX INTEGER); INSERT INTO "Z_PRIMARYKEY" VALUES(1,'Fugitive',0,0); CREATE TABLE Z_METADATA (Z_VERSION INTEGER PRIMARY KEY, Z_UUID VARCHAR(255), Z_PLIST BLOB); INSERT INTO "Z_METADATA" VALUES(1,'C945F467-6E9C-41F0-A4A9-D52873C4A780',X'62706C6973743030D50102030405060708090A5F101E4E5353746F72654 D6F64656C56657273696F6E4964656E746966696572735B4E5353746F7265547970655F101D4E5350657273697374656E63654672616D65776F726B56657273696F6E5 F10204E5353746F72654D6F64656C56657273696F6E48617368657356657273696F6E5F10194E5353746F72654D6F64656C56657273696F6E486173686573A05653514 C6974651101331003D10B0C5846756769746976654F102017B2EF9F16F877573E3C9CA8FF3C6E4F536F67658054DEE07005B5D5C53BC74D0813344060839FA0A7AAACA FB80000000000000101000000000000000D000000000000000000000000000000DB');
Run the inserts on your "correct structure" (in the simulator folder). Note the output below has some stuff skipped due to the paste speed. tford:~> sqlite3 /Users/tford/Library/Application Support/iPhone Simulator/3.2/Applications/C50BD46B-5B68-42B8-9646-A91471988418/Documents/iBountyHunter.sqlite SQLite version 3.6.12 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> INSERT INTO "ZFUGITIVE" VALUES(1,1,1,99064,1300,'Parole violator','David Adams'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(2,1,1,6077,56000,'Racketeering','Tracey Martin'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(3,1,1,56894,96000,'Embezzlement','Joe Daniels'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(4,1,1,12106,12000,'DUI','Mike Thayer'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(5,1,1,64235,25000,'Car Theft','Jim Smiley'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(6,1,1,56659,5000,'Petty theft','George Palin'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(7,1,1,98122,65000,'Kidnapping','Sarah Carr'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(8,1,1,45590,10000,'Missing person','Julie Gorman'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(9,1,1,56815,2300,'DUI after a bar fight he lost.','Vincent Grey'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(10,1,1,23594,32000,'Mean left hook, wanted for drug running.','Nick Forsee'); INSERT INTO "ZFUGITIVE" VALUES(11,1,1,89716,500,'Hunting license violation.','Hunter Sweeney'); INSERT INTO "ZFUGITIVE" VALUES(12,1,1,12359,56500,'Antisocial and tends to hide. Wanted for embezzlement.','Jim McCarthy'); INSERT INTO "ZFUGITIVE" VALUES(13,1,1,96986,22000,'Followed his dream of car theft.','Michael Merkins'); INSERT INTO "ZFUGITIVE" VALUES(14,1,1,12856,1200,'Escaped from an asylum.','Stanley Fisher'); INSERT INTO "ZFUGITIVE" VALUES(15,1,1,17887,22000,'Car theft and drug possession.','Henry Lewis'); INSERT INTO "ZFUGITIVE" VALUES(16,1,1,25961,1200,'Skipped out on college loans.','Jackson Jones'); INSERT INTO "ZFUGITIVE" VALUES(17,1,1,35805,67000,'Assault, and theft of a pet dog.','Fiona Westin'); INSERT INTO "ZFUGITIVE" VALUES(18,1,1,34571,500,'Running a mailbox baseball ring.','Mike Smithson'); INSERT INTO "ZFUGITIVE" VALUES(19,1,1,45982,45000,'Shop lifting jewelry.','Peggy Ford'); INSERT INTO "ZFUGITIVE" VALUES(20,1,1,12542,23000,'Illegal gambling operation.','Linda Lewis'); INSERT INsqlite> INSERT INTO "ZFUGITIVE" VALUES(11,1,1,89716,500,'Hunting license violation.','Hunter Sweeney'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(12,1,1,12359,56500,'Antisocial and tends to hide. Wanted for embezzlement.','Jim McCarthy'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(13,1,1,96986,22000,'Followed his dream of car theft.','Michael Merkins'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(14,1,1,12856,1200,'Escaped from an asylum.','Stanley Fisher'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(15,1,1,17887,22000,'Car theft and drug possession.','Henry Lewis'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(16,1,1,25961,1200,'Skipped out on college loans.','Jackson Jones'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(17,1,1,35805,67000,'Assault, and theft of a pet dog.','Fiona Westin'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(18,1,1,34571,500,'Running a mailbox baseball ring.','Mike Smithson'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(19,1,1,45982,45000,'Shop lifting jewelry.','Peggy Ford'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(20,1,1,12542,23000,'Illegal gambling operation.','Linda Lewis'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(21,1,1,22365,1200,'Illegal gopher hunging.','Randy Whitmore'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(22,1,1,34981,250,'Neighborhood fight over landscaping.','Kate Raines'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(23,1,1,74827,12000,'Lost a bar fight, badly.','Ameilia Bones'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(24,1,1,34523,45000,'Ran an illegal immigration ring.','Sam Romero'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(25,1,1,23409,55000,'Bomber for hire.','Jennifer Mai'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(26,1,1,9234,75000,'Illegal black ops coordinator.','Selina Horatio'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(27,1,1,87345,25000,'Assault, battery, and running away.','Nicky Wolf'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(28,1,1,44976,5800,'Bouncer for hire. ','Rudolph Granida'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(29,1,1,99856,89000,'Ran illegal investing ring. ','Ralph Gustav'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(30,1,1,32486,6700,'Dogfighting. Toy dogs.','N. Winner'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(31,1,1,23454,23000,'Stealing cool names from other industries.','Emmanuel Uttenburg '); sqlite> INSERT INTO "ZFUGITIVE" VALUES(32,1,1,9009,89000,'Tried to dump a guy in the river. Guy got away.','Samantha Fox'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(33,1,1,74624,2300,'Lost his boss'' dog. Boss was police chief.','John Irahia'); sqlite> INSERT INTO "ZFUGITIVE" VALUES(34,1,1,84643,5600,'Purse snatcher.','I. Stol eit'); sqlite>
Update the max primary key. and exit. sqlite> UPDATE "Z_PRIMARYKEY" SET Z_MAX=34 WHERE Z_ENT = 1; sqlite> .exit tford:~>
Copy the simulator version into your XCode project directory. Delete the simulator version. Turn your create code back on. Run it. The data should appear.

You might also try page 389, to migrate the data, however, you will also need to update the managed object model code (use the correct folder name):

 */
- (NSManagedObjectModel *)managedObjectModel {
	
    if (managedObjectModel != nil) {
        return managedObjectModel;
    }

    NSString *path = [[NSBundle mainBundle] pathForResource:@"_BountyHunter" ofType:@"momd"];
    NSURL *momURL = [NSURL fileURLWithPath:path];
    managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

    return managedObjectModel;

}

// See: http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html
// You might be able to skip this if you delete the app from the simulator, but I rather thought the point
// was to be able to update your app after it was deployed on zillions of phones.


About Me: