MSPersistentStoreCoordinator Has no persistent stores
Published by emacstheviking on Tue, 03/22/2011 - 18:14
RTFM: Page 42 of the iPhone_Development.pd file from Apple
Whilst developing an iPhone application that uses the Core Data system as the persistence mechanism, I added a new attribute to the source of type 'Binary Data' to hold a UIImage thumbnail.
I did a Clean All Targets and rebuilt and hit the big one to test it out an Whammo! Get a load of this for an error message...
2009-06-09 20:26:40.113 XXXXXXX[8815:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.'
Closer examination of the 'storeUrl' in the xcode supplied function shown here :-
/**
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: @"BopView.sqlite"]];
NSError *error;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
// Handle error
}
return persistentStoreCoordinator;
}
...gave me the location of an SQLite database. Having experienced problems like this before with other systems and technologies, the old Spidey Sense was tingling at this point and I assumed (correctly as it turned out) that the existing database was now out of step with the new model and that deleting it would probably solve my problems. (It did!)
Printing description of storeUrl:
{type = 15, string = file://localhost/Users/seancharles/Library/Application%20Support/iPhone%20Simulator/User/Applications/76A20700-173A-483D-9A40-108AD5DDB87B/Documents/BopView.sqlite, base = (null)}
However, finding the file was not quite as simple as the message indicated as when I drilled down to the location, it wasn't to be found! There are folders there and all I can say is that by expanding each folder in turn I found the one that contained my application and from there I managed to find the .sqlite file and delete.
(UPDATE: It happened again on my other Mac and this time the file-name *did* match so maybe it was too late to think when I wrote this at 11:40pm! Basically, find the .sqlite file and trash it!)
I then re-ran my program and created a new entry into my application with no problems so it seems that my initial hunch was correct; adding a new attribute to the data model meant that the existing SQLite database was no longer viable.
If anybody can throw further light on how to better deal with this, for example, have I missed something that xcode could have done for me perhaps then please let me know; this is the first time I have used Core Data in an iPhone application. And did I mention it is my first iPhone application too ?!
Add new comment