NSPersistentStoreCoordinator Crash - iphone

I recently updated from xcode 3.x to 4.2 and I am having issues with core data when I run apps in 4.2. I also updated to iOS 5 so maybe the issue is in there, I'm not really sure.
The apps ran fine in 3.x but crash in 4.2. The issue occurs whenever I tried to access a NSPersistentStoreCoordinator object. Here is an example of an area where the app crashes.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"GraffitiMap.sqlite"];
NSError *error = nil;
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator_;
}
It cashes at the line: persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
What am I missing about transitioning an app from xcode 3.x to 4.2, or upgrading to iOS 5?

I met with this problem before after I upgraded to Xcode 4.2 and iOS 5.
My app was keeping crash on [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; with error EXEC_BAD_ACCESS, I did a lot of tests to investigate where the problem is. Finally after I deleted all fetch requests in data model, the error gone and said another error "the entity name not found". So I was trying to delete fetch request one by one, and test again and again to figure out which is that "bad" fetch request. And I found that there are two fetch requests do same thing (have same criteria on same entity) although they have different name, than I deleted one of them, the error was fixed completely.
Today I meet with this problem again, and I'm sure that there is no duplicate fetch request this time, but the error still remain. I thought apple add some validations on CoreData like this in new iOS5, but can not find any docs which describe this.
Hope this help you

Related

How to migrate core data by deleting old one on App Update

Hi I'm going to update my iOS app in appstore and this update contains database change so now how to migrate my existing core data by deleting old database of existing version on App update?
I have referred Core Data Migration tutorial
Core Data Migration Post
Unfortunately of no use. Any help is appreciated in advance
Smith,
I presume you have done some schema changes, in the xcdatamodel
Always, Add a new Model Version (Select name.xcdatamodeld then Editor->Add model Version) before making any changes, if you have an app already submitted to App Store which is using the earlier model version.
Then,
Add a new file from Core Data Tab, as Mapping Model
Select, Source Model (Model Version which the submitted App is using)
Destination Model (Model Version in which you have done the Changes)
And you are done!
Is it possible you haven't created a new version of the DB model before you applied the auto migration?
Select [dbname].xcdatamodeld from project explorer.
Select Editor->Add model Version.
Select base it on your current model.
Make sure you have the automigrate option on like so:
-(NSPersistentStoreCoordinator *)storeCoordinator {
if (storeCoordinator_ != nil) {
return storeCoordinator_;
}
NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: #"[dbname].sqlite"]];
NSDictionary* storeOptions = #{NSMigratePersistentStoresAutomaticallyOption : [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption : [NSNumber numberWithBool:YES]};
NSError *error = nil;
storeCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self objectModel]];
if (![storeCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:storeOptions error:&error]) {
// handle error here and remove abort
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
return storeCoordinator_;
}
and away you go.

iOS 5 - Coredata Sqlite DB losing data after killing app

I'm using coredata with a sqlite DB to persist data in my app. However, each time I kill my app I lose any data that was saved in the DB. I'm pretty sure its because the .sqlite file for my DB is just being replaced by a fresh one each time my app starts, but I can't seem to find any code that will just use the existing one thats there.
It would be great if anyone could point me towards some code that could handle this for me.
Cheers
B
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"FlickrCoreData.sqlite"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
return __persistentStoreCoordinator;
}
Changes to a managed object context in core data are not saved at the time you make the changes for optimization purposes. This way you can make a bunch of changes to your context and then persist all the changes at once. So if you are killing your app before it has a chance to autosave you will then lose all your data. I'm guessing this is what you are experiencing here.
In any case, try explicitly making a call to save your data before closing your app. This should solve your problem.
For example, assuming you have a variable that holds your managed object context called context you can save your context by making the following call somewhere in your code before closing the app:
[context save:&error] or simply [context save:nil]
Have you tried place [self saveContext] in appDelegate function applicationWillTerminate:. You should save the context before terminate the application.

Testing Core Data on iPhone without connection to Xcode

Running the App on the iPhone works fine, but only if it stays connected to the Mac/linked to Xcode.
If I try to run it after I disconnected it (after stopping the Run), Core Data does not work anymore. Neither the Build nor the Debug configuration works (Product -> Edit scheme... -> Run xy.app -> Info -> Build configuration).
My xcdatamodel settings:
File Type: Default Core Data Model
Location: Relative to Group
Any ideas?
Cheers,
Saeppi
Sorry for not being more specific about my issue. There's no crash, the changes I thought I did to the Core Data Model just did not happen.
Reading a bit more about SQLite and how it works with Core Data, I admit that I committed a very stupid error: I copied the *.sqlite file from a tutorial and imported it into my Xcode project and copied it to the App's folder (and then renaming it of course). Removing the sqlite file causes now the following error:
error: /Users/myName/Documents/myApp/myApp.sqlite: No such file or directory
My PersistentStoreCoordinator:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: #"MyApp.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"ErrorKey", nil)
message:NSLocalizedString(#"ErrorDBKey", nil)
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
return persistentStoreCoordinator;
}
and my application's directory:
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
I thought Core Data would generate a new sqlite file once it's been removed from the folder. What's the error in reasoning?
Does it crash on device?
You can connect the device and check the crash report in device logs.It will give you better idea about what is happening.Secondly try to quit app from background and run.
I would suggest check the crash logs on device, if it's not able to create or find the core data it will give a message like: store missing or something like that.
Most likely you are opening your db file in the main bundle. Main bundle is read only. Your db file needed to be in the app's document folder.
Checkout this SO post

iPhone Core Data Lightweight Migration Cocoa error 134130: Can't find model for source store

Folks,
Lightweight migration is failing for me 100% of the time on this line:
[persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]
with the error:
Error: Error Domain=NSCocoaErrorDomain Code=134130 UserInfo=0x4fbff20 "Operation could not be completed. (Cocoa error 134130.)"
"Can't find model for source store";
Here is my managed object context, model, and persistent store:
- (NSManagedObjectContext *) managedObjectContext {
if (managedObjectContext != nil) {
return managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator: coordinator];
}
return managedObjectContext;
}
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
return managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: #"Locations.sqlite"]];
NSError *error;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
// Allow inferred migration from the original version of the application.
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(#"Error: %#",error);
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
I have two versions of my model in my project: a version 4 and a version 5. If I set my version 4 as default, it works fine. If I select "Design -> Data Model -> Add Model Version" (as described by this post), make a change, Design -> Data Model -> Set Current Version, build and run, it will fail with the aforementioned "Can't find model for source store" error. Set model back to version 4, no problems, addPersistentStoreWithType. Alternatively, if I add model version and make no changes, simply go from version 4 to 5 without adding any new fields, no problems. If I then try to go from 5 to 6, the aforementioned error.
This code is failing on both Simulator and Phone. I read several prescriptions calling for deleting and reinstalling the app, which does work for both Simulator and Phone, but I am afraid that when I release this to real users it will break my installed base since they won't be able to delete and reinstall - App Store will auto-upgrade them.
This code worked in releases past with no changes on my part - hence my ability to make it all the way up to version 4. I recently upgraded to XCode 3.2.3 building for iOS4, which may have something to do with this.
Is anyone else having this issue all of a sudden now like I am? Has anyone managed to work past it? Thanks.
PS - For Googlers who stumble on this page, here are all the relevant pages you might consider reading, below. Unfortunately none of these solved my issue.
Implementation of "Automatic Lightweight Migration" for Core Data (iPhone)
http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html
https://stackoverflow.com/questions/2925918/iphone-core-data-lightweight-migration-error-reason-cant-find-model-for-sour
iPhone Core Data "Automatic Lightweight Migration"
http://www.iphonedevsdk.com/forum/iphone-sdk-development/38545-coredata-migration-issues.html
UPDATE
While this is not a real fix, it does avoid the scenario of a crashing client: simply delete the database file:
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
// Delete file
if ([[NSFileManager defaultManager] fileExistsAtPath:storeUrl.path]) {
if (![[NSFileManager defaultManager] removeItemAtPath:storeUrl.path error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
}
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error])
{
// Handle the error.
NSLog(#"Error: %#",error);
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
}
UPDATE 2
Here is what happens when I inspect VersionInfo.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSManagedObjectModel_CurrentVersionName</key>
<string>Profile 5</string>
<key>NSManagedObjectModel_VersionHashes</key>
<dict>
<key>Profile</key>
<dict>
<key>Profile</key>
<data>
ZIICGgMBreuldkPXgXUhJwKamgwJzESM5FRTOUskomw=
</data>
</dict>
<key>Profile 2</key>
<dict>
<key>Profile</key>
<data>
tEB7HrETWOSUuoeDonJKLXzsxixv8ALHOoASQDUIZMA=
</data>
</dict>
<key>Profile 3</key>
<dict>
<key>Profile</key>
<data>
qyXOJyKkfQ8hdt9gcdFs7SxKmZ1JYrsXvKbtFQTTna8=
</data>
</dict>
<key>Profile 4</key>
<dict>
<key>Profile</key>
<data>
lyWDJJ0kGcs/pUOModd3Q1ymDvdRiNXui4NCpLxDFSw=
</data>
</dict>
<key>Profile 5</key>
<dict>
<key>Profile</key>
<data>
V4PyRK1ezj3xK1QFRCTVzGOqyJhEb7FRMzglrTsP0cI=
</data>
</dict>
</dict>
</dict>
</plist>
Here is the code that I wrote to inspect my model (note I had to go out and add a base64 encoder, since that is what is in the VersionInfo.plist file)
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSDictionary *storeMeta = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:nil URL:storeUrl error:&error];
NSLog(#"%#",storeMeta);
id someObj = [[storeMeta objectForKey:#"NSStoreModelVersionHashes"] objectForKey:#"Profile"];
NSLog(#"%#",someObj);
NSLog(#"%#",[NSString base64StringFromData:someObj length:[someObj length]]);
And here is the debug output:
{
NSPersistenceFrameworkVersion = 310;
NSStoreModelVersionHashes = {
Profile = <97258324 9d2419cb 3fa5438c a1d77743 5ca60ef7 5188d5ee 8b8342a4 bc43152c>;
SerializedMessage = <4530863c d943479a edfb4dfb 5059c28d d6137dc4 d1153d36 ed52be49 11074f13>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
);
NSStoreType = SQLite;
NSStoreUUID = "823FD306-696F-4A0F-8311-2792825DC66E";
"_NSAutoVacuumLevel" = 2;
}
<97258324 9d2419cb 3fa5438c a1d77743 5ca60ef7 5188d5ee 8b8342a4 bc43152c>
lyWDJJ0kGcs/pUOModd3Q1ymDvdRiNXui4NCpLxDFSw=
As you can see, that last line that starts with 'ly' matches Profile 4 in VersionInfo.plist...hence I see no reason why it should be failing. Any other ideas?
I read several prescriptions calling
for deleting and reinstalling the app,
which does work for both Simulator and
Phone, but I am afraid that when I
release this to real users it will
break my installed base since they
won't be able to delete and reinstall.
This is a problem caused by Xcode not removing old momc files from simulator/dev-device when a the model file is changed e.g. changing the name. The old file remains which causes confusion. This is something you only see during development because it is an artifact of the way that Xcode manipulates the app bundle without completely reinstalling it every time as must happen with a release version.
You can confirm this logging the return of:
[[NSBundle mainBundle] URLsForResourcesWithExtension:#"momc"subdirectory:nil];
... which should show you all the compiled model files in the app bundle
It is bad practice to rely on migration during development because it is very common for migration to fail if you are making changes to the model and store. You should only use migration after all the code is nailed down. I would also recommend regenerating your store from scratch every time you run. It is to easy to build up garbage in the store by changing up the model.
I've read over your updated question. It's getting quite messy with model versions.
You should try and audit the version of the model that the existing store is actually asking for, and try to list all available models in the app bundle at runtime.
I look in my apps' model directory
NSString *modelDirectoryPath = [[NSBundle mainBundle] pathForResource:#"MyModel" ofType:#"momd"];
I'm not sure if developers normally do this, but I keep my model versions with different names.. so I have in there:
VersionInfo.plist
MyModel.mom
MyModel2.mom
The version hashes listed in the VersionInfo.plist should help you troubleshoot. Look for the version hash required by the existing persistent store, and see if you can locate it in the version hashes listed in VersionInfo.plist.
Actually, I can't see a way to write some code that will ask the persistent store what it's entity version hashes are. The NSPersistentStoreCoordinator or the NSMigrationManger seem to be doing that privately. i.e. they check the persistent store entity versions against the model that the store is loaded with.
Had another quick look, and it's available in the store meta data. Nice and easy!
NSError *error;
NSURL *storeURL = [NSURL fileURLWithPath:[[self class] storePath]];
NSDictionary *storeMeta = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:nil URL:storeURL error:&error];
And looking in storeMeta I get a key with
<CFString 0x7328050 [0x2724380]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x7328340 [0x2724380]>{type = immutable dict, count = 5,
entries =>
0 : <CFString 0x7328110 [0x2724380]>{contents = "MyEntityNameOne"} = <CFData 0x73281b0 [0x2724380]>{length = 32, capacity = 32, bytes = 0x143325cf121239ce156af2e2a1aad7d9 ... 976977fdf29fc013}
1 : <CFString 0x7328130 [0x2724380]>{contents = "MyEntityNameTwo"} = <CFData 0x7328200 [0x2724380]>{length = 32, capacity = 32, bytes = 0x0ca6ecf1283d12bd3ca82af39b6b9f5d ... 149dd39a591e0c4d}
... }
Should be easy to iterate over that NSStoreModelVersionHashes dictionary and log the version hashes your store requires.
Manually match that back to the ones available in VersionInfo.plist and see what's missing. Perhaps there's not one single model that contains all the required versions of the entities in your existing persistent store. That might happen due to (accidental?) edits on the model before or after setting up a new model version?
I had esilver's exact problem and found this question via Google. However, the fix that worked for me wasn't anywhere else on SO (that I know), so here goes:
If there are multiple copies of your *.mom files (compiled object models) in your bundle, Core Data may become confused when attempting to migrate on your behalf.
Our problem was that each individual model file (Data.xcdatamodel, Data_V1.xcdatamodel, Data_V2.xcdatamodel, etc.) was not only inside the xcdatamodeld/ directory (which was included as something to compile in the build process), but also each file was also included in the "Compile Sources" list.
What this meant is that the resulting bundle had two sets of *.mom files: one inside xcdatamodeld/ and one at the top level. I think Core Data became very, very confused, and led to this error. Removing each xcdatamodel file from the "compile sources" and leaving the xcdatamodeld directory solved the problem for us (e.g. got auto-versioning up and running again). Hope this helps!
Well in my case exactly the same thing was happening and i was on iOS 7 and this problem screwed my head for at least a week and then finally find the solution which works for me
.
In order to make it work you have to add an extra value in options which is used to add PersistentStore and then you go( I am not sure about other iOS version but yeah it will definitely work on iOS 7).
-(NSManagedObjectModel *)managedObjectModel
{
if (managedObjectModel != nil)
{
return managedObjectModel;
}
managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
return managedObjectModel;
}
-(NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (persistentStoreCoordinator != nil)
{
return persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"ABC.sqlite"];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] ini tWithManagedObjectModel:[self managedObjectModel]];
//Creating Lightweight migration.
NSDictionary *options =
#{
NSMigratePersistentStoresAutomaticallyOption:#YES
,NSInferMappingModelAutomaticallyOption:#YES
,NSSQLitePragmasOption: #{#"journal_mode": #"DELETE"}
};
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
Folks,
For the record, I ceased use of core data completely. My code was complicated and, per the issues above, unreliable. I use SQLLite directly now and am WAY happier. I cannot recommend using Core Data in any scenario.

CoreData could not fulfill a fault when adding new attribute

I am receiving a "CoreData could not fulfill a fault for ..." error message when trying to access a new attribute in a new data model. If I work with new data I'm ok, but when I attempt to read existing data I get the error. Do I need to handle the entity differently myself if the attribute isn't in my original data? I was under the impression that Core Data could handle this for me. My new attribute is marked as optional with a default value.
I have created a new .xcdatamodel (and set it to be the current version) and updated my NSPersistentStoreCoordinator initialization to take advantage of the lightweight migration as follows:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeUrl options:options error:&error])
{
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
Any help is appreciated.
UPDATE:
After more digging I've updated my managedObjectModel to:
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
//managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
NSString *path = [[NSBundle mainBundle] pathForResource:#"< MyModel >" ofType:#"momd"];
NSURL *momURL = [NSURL fileURLWithPath:path];
managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];
return managedObjectModel;
}
This still hasn't resolved my problems. I've clean and rebuilt, but still no love.
How are you constructing your NSManagedObjectModel? If you are passing it a specific file that might be causing your issue as you may be loading the older, original mom file that is lingering around your project. Ideally you should be now loading the momd bundle or just loading all compiled models from your bundle using:
NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:nil];
Which, if you receive an error, indicates that you need to clean your project to get rid of stale compiled models.
Update
Since it is not an old model issue, we move onto the next possibility. That the version is not set correctly in the plist. To check this, use finder or terminal and look inside of the momd bundle and open the plist therein. Check that to confirm that the new model is indeed set as the current version.
Assuming that does not work, next run your app in the simulator and have it save immediately upon creation of the MOC. After that, open the sqlite3 file using the command line tool and check the schema to see if it has updated to the new structure.
Assuming that is set correctly, are you using custom NSManagedObject subclasses?
Turns out that there was no problem with the versioning. I had some rather (too) complex logic which removed my object from the model and then I later tried to access it.
+1 to Marcus for the additional debugging pointers, they will no doubt come in handy at some point.