1
votes

There are a few Lightweight Migration questions on Stack Overflow already, but most of them have extra wrenches in the mix. I'm doing the most basic migration possible and it's failing. I've done this several times in the past with no issue, so this is getting quite frustrating. It feels like this might be a problem with Xcode 4, which is just terrible when it comes to working with Core Data.

I've got my old model version (actually a few old versions) and a new version which is marked active. I have the two options booleans set, automatically migrate and infer:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

The only difference between my last active model and my new one is a single new attribute (Date) which is optional. As far as I know, a single new optional attribute shouldn't cause any issues with lightweight migration.

I run the app and I get "Can't find or automatically infer mapping model for migration" which seems absurd. There's only a single change - and it's optional!

What am I missing? It must be something stupid.

1
maybe one of you models is not a member of the target you are running?sgosha

1 Answers

1
votes

As you stated, just adding a column shouldn't raise that error. This error is typically raised when for instance unsetting an optional field (CoreData then doesn't know what to do with existing NULL values) or changing a field type. Which is not your case. You might have accidentally clicked somewhere...

To diagnose what's happening, surround your code with @try{}@catch{}, which I guess you already doing, and give a look at catched Exception e.userInfo property, most of the time CoreData gives all details about what caused the error, like which Field, which reason... That might help!

You could also simply delete last model version and recreate it, since there is only one small change.