core data “Can't find model for source store”;

对着背影说爱祢 提交于 2019-12-30 11:33:30

问题


Heres the problem... I Have an app in the app store, which uses core data... I have been updating my model correctly (using versions etc) but Just recently I have accidentally lost my latest model (the one that corresponds with the app store) and so now I get this error: reason = "Can't find model for source store";

I have created my model and to the best of my knowledge I have made the changes exactly the same from the previous version... yet I still can't get it to like my model version. So my question is, can I somehow trick core data to thinking it has the right version? or is there a way I can check which entities its having trouble with? I understand that core data stores a hash of the model to check that the versions are the same, but I don't know the extent to which the version models have to be the same in order for the 'hash check' to be successful..

Any help would be great! Thanks!


回答1:


You can recover the data model from an app store copy of your app, and import that back into your project. Core Data models don't get compiled in the same way that source code does, so reversing the process is usually effective. The following assumes that you have downloaded the current app store version of the app in iTunes on your Mac:

First copy the app store bundle to a safe place:

cp ~/Music/iTunes/Mobile\ Applications/YOUR-APP-NAME.ipa /tmp
cd /tmp/

Next open up that package, which is really just a zip file.

unzip YOUR-APP-NAME.ipa

This creates a directory called Payload that contains the app and its bundle. The bundle contains the Core Data model. Copy that out of the bundle:

cp -rp Payload/YOUR-APP-NAME.app/YOUR-MODEL-NAME.momd /tmp/

(adjust the name to match your data model).

If you already have more than one version in the app store, the model is a momd that contains multiple mom files. Each mom file corresponds to a model version. One of them is the one you need. You'll need to figure out which is which.

Now, switch to Xcode. Create a new version of the data model but don't make it current. Delete everything in this version, all entities, everything. With the now-empty model displayed, go to the Editor menu and select Import.... In the file open dialog, navigate to the copy of your data model in /tmp/ from above. Select the version you need to recover and click "Open".

All of the entities from that version of the model are now present in the new model file you just created. You can now use this model as the "original" model when doing model migration.

Alternatively, instead of importing into Xcode, you can use my momdec project to decompile the model in place. That will produce an uncompiled Core Data model that you could add to your Xcode project.




回答2:


For future reference and not recommended.

If the model is unrecoverable, you can "fake it".

  1. Create a new model that is identical to the one you lost
  2. Test it and see if you get lucky (unlikely).
  3. Write down the entity hashes that Core Data spits out in the log
  4. Input those hashes into the model as overrides in the (Version Hash Modifier)
  5. Run your migration again.
  6. Never ever modify the production model again. Check it into source control immediately on shipping.



回答3:


For anyone showing up on this question who is not trying to migrate a core data model to another this error can also show up if you are trying to save data to core data that has some values in your entity not being set. Make sure all your data variables are being set and set correctly to avoid this error that dreams of MacBook Pros riding unicorns may live forever in your reality!



来源:https://stackoverflow.com/questions/21306257/core-data-cant-find-model-for-source-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!