Reputation: 3139
I built a brand new xcode project without checking 'use core data'.
I implemented my own coredata helper class to setup the stack.
I created an xcdatamodel file, i reference it in my stack to setup core data. It works.
Whenever I create an entity, then create an NSManagedObject subclass of it, I get this huge error.
2015-08-04 11:27:03.524 Himachal[3070:715719] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/3261B814-C246-4937-92E6-6652F6E29AAB/Library/Application%20Support/DataModel.sqlite options:{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x1710765c0 {URL=file:///var/mobile/Containers/Data/Application/3261B814-C246-4937-92E6-6652F6E29AAB/Library/Application%20Support/DataModel.sqlite, metadata={
NSPersistenceFrameworkVersion = 519;
NSStoreModelVersionHashes = {
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "96440757-DC46-4B3D-BD88-88741E0B3337";
"_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store} with userInfo dictionary {
URL = "file:///var/mobile/Containers/Data/Application/3261B814-C246-4937-92E6-6652F6E29AAB/Library/Application%20Support/DataModel.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 519;
NSStoreModelVersionHashes = {
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "96440757-DC46-4B3D-BD88-88741E0B3337";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
2015-08-04 11:27:03.526 Himachal[3070:715719] CoreData: annotation: NSPersistentStoreCoordinator's current model hashes are {
Test = <1bf25eb0 2a3759be 4e86d088 de4f2a7e 350d3228 3cae66b5 1f628c4a 98f43e45>;
}
2015-08-04 11:27:03.526 Himachal[3070:715689] Core Data stack setup failed.
I tried looking for people with similar errors but they all have to do with database migrations. There must be a single thing I'm doing wrong, maybe I haven't labeled something properly. Any ideas?
Upvotes: 0
Views: 889
Reputation: 37290
According to the docs, "You can only open a Core Data store using the managed object model used to create it. Changing a model will therefore make it incompatible with (and so unable to open) the stores it previously created." Thus you receive an error if you try to run the app with one core data model, change your core data model by adding an entity, then running the app again.
As long as you app has yet to be deployed to the app store, it may be easier to just delete the app from your device and run a fresh version with the brand new data store in order to circumvent that issue. But if your app's already out in the world, you obviously don't want the app to crash for your users so you have to programmatically change the old core data model to be compatible with the new version by performing something called a "Data Migration." Here's a good tutorial about how to perform a lightweight core data migration if your current scenario requires one: http://www.raywenderlich.com/27657/how-to-perform-a-lightweight-core-data-migration .
Upvotes: 2