After the COREDATA database structure was changed, the new version was not created immediately upon request, but was modified on the original version before it was remembered to create a new release. and merge the database with the following code,
Nserror *error =Nil; Nsdictionary*options =[nsdictionary dictionarywithobjectsandkeys: [NSNumber Numberwithbool:yes], Nsmigratepersi Stentstoresautomaticallyoption, [NSNumber Numberwithbool:yes], Nsinfermappingmodelautomaticall Yoption,nsfileprotectioncomplete, Nspersistentstorefileprotectionkey, nil]; _persistentstorecoordinator=[[Nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:[self Managedobjectmodel]]; if(! [_persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype Configuration:nil URL:storeURL options:o Ptions error:&ERROR]) {NSLog (@"unresolved error%@,%@", error, [error userInfo]); Abort (); }
The result is that the can ' t find model for source store is a bug. Let's take a look at the answers on StackOverflow.
Your SQLite Database'S model hash must match one of the mom or MOMD created by your xcdatamodel when you build your app. You can see the hashes in the MOMD'S versioninfo.plistinchThe built app's bundle. See below for code to find your database'S model Hash. soifYou change your xcdatamodel instead of creating aNewVersion under Xcode->editor->add model Version ... then your model's hash would be different, and Addpersistentstorewithtype won't be able-your old database, which used the old model. That's what causes the "Can'T find model forSOURCE Store"error.
Let's take a look at the version file in the bundle based on this answer.
Before the change
Then look at the changed
Note that the hash value of the profile model in the same version 6 is inconsistent, so it is crash.
Why would crash, because the old version of the update to the new version, documents in the database is unchanged, the change is in the bundle of. momd file plus the MOM file and version of the plist. After the new version is updated, the old version of the mom file is retained, and the MOM file is referenced to read the old version of the database and merge with the new version database. If the old version of the mom file is changed in the new version, the program cannot read the old version data and throws an exception.
The workaround is also simple, locate the XXXX 6.xcdatamodel file that was used in the previous version, and replace the. xcdatamodel file that was incorrectly changed.
IOS CoreData Database Upgrade times can ' t find model for source store