CD database breaks after lightweight migration?
CD database breaks after lightweight migration?
- Subject: CD database breaks after lightweight migration?
- From: Fritz Anderson <email@hidden>
- Date: Thu, 20 Oct 2011 14:03:42 -0500
Xcode 4.2, iOS 5.0 SDK, iOS Simulator for 4.3.
I'll do the short version of this, in case there's a well-known answer. If we need to get into code, I'll be glad to supply it.
I added a version to my data model* and added an attribute to one of my entities. It is Boolean, non-optional, and defaulted to NO.
When I create my NSPersistentStoreCoordinator, I pass NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption, both NSNumber YES, as options to addPersistentStoreWithType:....
With assertions, I verified that my new attribute is present in the model. The "~" file appears. I used a third-party SQLite viewer to verify that in the old database, the attribute is absent, in the new one, it is present.
I do a fetch in the MOC. As it happens, it's on a different entity, but it has a relationship to the changed entity, and prefetches the relationship. I verified with that SQLite viewer that an object matching the query is present in the DB.
The fetch succeeds, but the result is a fault. Attempting to fire the fault by sending it a valueForKey: simply produces a no-such-key exception (meaning it's still a fault).
My impression had been that adding an attribute with a default was the canonical case in which lightweight migration should work. The SQLite tables do in fact migrate (though I can't speak for the metadata).
Does it in fact not work? Or is there something else I should be frobbing?
— F
* (Hint for Xcode 4 users: The CD documents are obsolete on how to make your new version the current one. Select the .xcdatamodel_d_ in the Project navigator, and use the File inspector to select your new version as current. I haven't found this documented anywhere.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden