The Model Used to Open the Store Is Incompatible With the One Used to Create the Store

reason = The model used to open the store is incompatible with the one used to create the store

Choose Finder and go to Library from Go by clicking option button on keyboard. then search on library using your app Bundle Identifier. delete the folder with it. then Re-launching your application will recreate the folder with no data and you can start re-populating it according to your new model.

The model used to open the store is incompatible with the one used to create the store Xcode 7.1

That error means that you changed the model so that it doesn't match the one you were using when you created the app's data. It's the classic sign of changing a data model and not either doing model migration or deleting the app from the phone/simulator (and it's been pretty much the same as long as Core Data has existed, so old information is not irrelevant). Deleting the app from the simulator would normally be all that's needed to run the app again. If it's not working, then you're somehow leaving old data in place.

The best way to delete an app from the simulator is usually the same as you'd delete an app on a real device-- click and hold until the app icon starts moving, then click the "x" on its icon to delete it.

If deleting the app doesn't help, you're using old data some other way. Maybe you have some pre-loaded data built into the app that was configured using an old version of the model?

Core Data: The model used to open the store is incompatible with the one used to create the store

I found a solution reading this article. Even if i don't understand why it works...

- (void)initializeCoreData{
// Initialize models
NSURL *db2ModelURL = [[NSBundle mainBundle] URLForResource:@"villes" withExtension:@"momd"];
NSManagedObjectModel *db2Mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:db2ModelURL];
NSAssert(db2Mom != nil, @"Error initializing Managed Object Model");

NSURL *db1ModelURL = [[NSBundle mainBundle] URLForResource:@"MMAMeteoPro" withExtension:@"momd"];
NSManagedObjectModel *db1Mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:db1ModelURL];
NSAssert(db1Mom != nil, @"Error initializing Managed Object Model");


NSManagedObjectModel * fullModel=[NSManagedObjectModel modelByMergingModels:[NSArray arrayWithObjects:db1Mom,db2Mom, nil]];

// Initialize context
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:fullModel];
NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[moc setPersistentStoreCoordinator:psc];
[self setManagedObjectContext:moc];

// Initialize stores
NSURL *db2StoreURL = [[NSBundle mainBundle] URLForResource:@"db2" withExtension:@"sqlite"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *documentsURL = [[fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *db1StoreURL = [documentsURL URLByAppendingPathComponent:@"db1.sqlite"];

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
NSError *error = nil;
NSPersistentStoreCoordinator *psc = [[self managedObjectContext] persistentStoreCoordinator];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
NSMutableDictionary * db2Options=[NSMutableDictionary dictionaryWithObjectsAndKeys:
@{@"journal_mode":@"DELETE"},NSSQLitePragmasOption,
@YES, NSReadOnlyPersistentStoreOption,
nil];
NSMutableDictionary * db1Options=[NSMutableDictionary dictionaryWithObjectsAndKeys:
@{@"journal_mode":@"DELETE"},NSSQLitePragmasOption,
nil];
NSPersistentStore * tempStore = [psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:db2StoreURL options:options error:&error];
NSAssert(error == nil, @"Error initializing PSC: %@\n%@", [error localizedDescription], [error userInfo]);
[psc removePersistentStore:tempStore error:&error];
NSAssert(error == nil, @"Error initializing PSC: %@\n%@", [error localizedDescription], [error userInfo]);
tempStore=[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:@"DB2Conf" URL:villeStoreURL options:db2Options error:&error];
NSAssert(error == nil, @"Error initializing PSC: %@\n%@", [error localizedDescription], [error userInfo]);
tempStore=[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:@"DB1Conf" URL:meteoStoreURL options:db1Options error:&error];
NSAssert(error == nil, @"Error initializing PSC: %@\n%@", [error localizedDescription], [error userInfo]);
});

}

We have to:

  1. Add the ReadOnly persistent store first, with the lightweight migration options on, and no ReadOnly option nor configuration
  2. Remove this persistent store (???)
  3. Add it again, this time without the lightweight migration options, but with the ReadOnly and the good configuration.
  4. Add the Read/Write Persistent Store

If someone can explain me why this configuration works... Cause i really don't get the point here.

What to do when get The model used to open the store is incompatible with the one used to create the store?

Or if you're in dev mode, you can also just delete the app and run it again.

cocoa error 134100 again again (The model used to open the store is incompatible with the one used to create the store)

I found it by trials but I can't explain why...
Just set the configuration to nil instead of @"Default" when adding the store.

What to do when get The model used to open the store is incompatible with the one used to create the store?

Or if you're in dev mode, you can also just delete the app and run it again.



Related Topics



Leave a reply



Submit