简体   繁体   中英

Core Data Model Versioning and Data Migration

i want to app version update,but at the new version i add two new attribute at the core data,i want to Migrate data from old version to new version. my step:

  1. choice .xcdatamodeld file,then editor->Add Model Version
  2. Design > Data Model > Set Current Version.
  3. modify options

      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]) 

but my new version no found any data from the old version. how to modify it.

i found my mistakes: PushNoticationModal.sqlite not the same as the name PushNoticationModel.xcdatamodel ,you see PushNoticationModal not like PushNoticationModel.

when you only build one sqlite,the name PushNoticationModal.sqlite ,not the same as PushNoticationModel.xcdatamodel,your app also can run.but when you build migration you should keep the same

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM