First, lightweight migration
I. Suitable for the scene
Simple addition of a new attribute
Removal of an attribute
A non-optional attribute becoming optional
An optional attribute becoming non-optional, and defining a default value
Renaming an entity or property
II. How to Do
1. Set Persistent Store:
Nsdictionary *persistentstoreoptions = @{nsmigratepersistentstoresautomaticallyoption: @YES,
Nsinfermappingmodelautomaticallyoption: @YES};
PersistentStore = [_persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil URL: Storeurl options:persistentstoreoptions error:&addstoreerror];
2. Add a version to Database.xcdatamodel
Select Database.xcdatamodel, Editor, Add Model Version, and then set which data model file for the current database is the right one.
3. This will be done. So easy and simple. And this kind of migration mode, occupy most of database data migration application scenario.
Second, multiple Passes
This technology, I have not yet encountered the need to use its scene, so did not take the time to study. As for how to deal with, can refer to a very good blog, http://www.cnblogs.com/liyufeng2013/p/3782351.html
Apple official doc:https://developer.apple.com/library/prerelease/ios/documentation/cocoa/conceptual/ Coredataversioning/articles/vmmappingoverview.html#//apple_ref/doc/uid/tp40004399-ch5-sw1
Core Data Database Migration