IOS CoreData Database Upgrade times can ' t find model for source store

Source: Internet
Author: User
Tags sqlite database

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.