I have tried to perform a migration of my Core Data store using the manual migration with the NSMigrationManager. I have created a mapping model in Xcode (version 4) using the default wizard, then in the code found it using
[NSMappingModel mappingModelFromBundles:nil forSourceModel:sourceModel destinationModel:targetModel];
which seemed to work fine. The only problem is that after I tried to tweak the mapping model a little bit (using the method described here to split one entity into two), the previous method doesn't work anymore, it just returns nil (which would mean the mapping model is no longer compatible with the source and destination models ?!). Also, the funny thing is that Xcode shows me dropdowns with both source and destination models开发者_运维百科 for the mapping model which haven't changed and are set to the correct models.
How does the compatibility check work and are there really some changes to the mapping model that can render it incompatible to the original combination of source / destination model.
UPDATE: After uninstalling the app from the simulator and restoring the sqlite database, it works once again, which looks to me as if some of the models wasn't updated correctly.. strange enough, I am now wondering whether this can happen during a real update or it's just an Xcode / Simulator issue..
Every time you use a mapping model to do a migration it alters the persistent store. You have to start with the same version of the store every time and perform the migration in the exact same order to get the same results.
I would generally recommend routinely deleting and recreating stores used in development. Usually I do so at the start of every test run even if the data set is fairly large. If you don't do this, then you run the risk of building up "kruft" in the store by changes you make in the developing code.
精彩评论