Core Data: Error, “Can't Merge Models With Two Different Entities Named 'foo' ”

前端 未结 9 1005
醉梦人生
醉梦人生 2020-12-05 02:24

I\'m working on an iPhone app that uses Core Data. Most times, I just test in the simulator, but occasionally pump the app down to the iPad to make sure.

I\'ve recen

相关标签:
9条回答
  • 2020-12-05 03:01

    I had the similar problem after renaming database model. After cleaning, rebuilding and reinstalling app -- the same consequences: two different named .momd bundles with the same content appears in the application bundle (oldname.momd and newname.momd).
    I solved this problem by changing "Tools version" from 4.1 to 3.2 in "Core Data Model" (File inspector of Data Model) panel. After this I completely cleared up and re-builded the project, then changed back this property to 4.1 and again re-cleared and re-builded the app.
    In this case Xcode makes two files "layout" and "elements" (for older version compatibility) against "contents" in *.xcdatamodeld bundle, this cause that Xcode's data model compiler rechecks name of the model and there all will be ok with .momd bundles in the app's sandbox -- only one appears after reinstalling the app.

    0 讨论(0)
  • 2020-12-05 03:01

    You're eventually going to want to read about model migration so you can automatically update the core data database on the device when users upgrade.

    But if you're in dev and you don't have any installed users, you can wipe out the core data database by going into iTunes with your device connected, deleting the app from your device, and syncing. Then drag the new version of your app into iTunes and re-sync. You should have a clean model.

    0 讨论(0)
  • 2020-12-05 03:02

    Your error message doesn't mean you have two databases i.e. persistent stores. It means you have two overlapping model files (which are source files) in the Xcode project itself. Deleting the build does not good because the project just recreates the error upon the next build.

    Model files cannot overlap. You need to remove the duplication. The duplication comes from either (1) having two versions of the same file or (2) having two model files with the same entity in both.

    For (1), you need to remove the older duplicate. The model files have an extension of modelName.xcdatamodel. To find the duplicate, open the target and check under Compile Sources. All the model files included in the target will be listed there. Remove the duplicate.

    For (2), you can have as many model files as you like but you can't have two model files with the same entity in both. Sometimes, Core Data novices try to link to model files together by having them share one or more entities. If you've done that, you will need to remove the duplicate entity from one of the models.

    0 讨论(0)
  • 2020-12-05 03:08

    for me only the "Reset content and settings" of the simulator worked. otherwise I could not find any problems with my project.

    0 讨论(0)
  • 2020-12-05 03:14

    Delete the app from your iPad, then restart it. After the iPad has rebooted, do a clean build.

    0 讨论(0)
  • 2020-12-05 03:14

    I had the same problem.
    Try to clean Shift + Cmnd + K and cleaning build folder ALT + Shift + Cmnd + K in Xcode. This worked for me fine.

    0 讨论(0)
提交回复
热议问题