Compilation failed for data model at path after upgrading Xcode - ios

After upgrading to Xcode 4.3.2 I have started getting the following error when i do a build:
Compilation failed for data model at path '/Users/Administrator/Library/Developer/Xcode/DerivedData/AppName-ffeggcadwojrwacrwosvadafamrk/Build/Products/Debug-iphoneos/Data.momd/Data.mom'
This was not happening before the upgrade and if i check out the same project on machine running the previous version of Xcode it works fine. No Errors.
I have found a couple of similar posts here and here but none of the answers have helped at all. From the error message the file path it gives doesn't contain a file so i'm guessing its a property somewhere that i need to change but i just can't find it.
Please help, thanks.
EDIT: On further investigation, i can stop it from erroring if i remove certain entities from the data model file, we are currently using a large pre created sqlite file to load data so i could recreate the data model file but that would mean recreating the sqlite which would be a bit of a pain. Anyone know why certain entities cause this?

Related

Build failed--attribute must have a defined type

My app crashes on build. Here's the error in it's entirety:
DataModelVersionCompile /Users/AAAAAAA/Library/Developer/Xcode/DerivedData/XXXXXXXXXX-envirswdnpegjccdpxakhoykfnfq/Build/Products/Debug-iphonesimulator/XXXXXXXXXX.app/WMMGDataModel.momd XXXXXXXXXX/WMMGDataModel.xcdatamodeld
cd "/Users/AAAAAAA/Desktop/Everything from DT 1:20:15/App projects/WMMG/XXXXXXXXXX"
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/momc -XD_MOMC_SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -XD_MOMC_IOS_TARGET_VERSION=8.1 -MOMC_PLATFORMS iphonesimulator /Users/AAAAAAA/Desktop/Everything\ from\ DT\ 1:20:15/App\ projects/WMMG/XXXXXXXXXX/XXXXXXXXXX/WMMGDataModel.xcdatamodeld /Users/AAAAAAA/Library/Developer/Xcode/DerivedData/XXXXXXXXXX-envirswdnpegjccdpxakhoykfnfq/Build/Products/Debug-iphonesimulator/XXXXXXXXXX.app/WMMGDataModel.momd
/Users/AAAAAAA/Desktop/Everything from DT 1:20:15/App projects/WMMG/XXXXXXXXXX/XXXXXXXXXX/WMMGDataModel.xcdatamodeld/WMMGDataModel 5.xcdatamodel:WMMGAccount.attribute: error: WMMGAccount.attribute must have a defined type
/Users/AAAAAAA/Desktop/Everything from DT 1:20:15/App projects/WMMG/XXXXXXXXXX/XXXXXXXXXX/WMMGDataModel.xcdatamodeld:0: error: Compilation failed for data model at path '/Users/AAAAAAA/Library/Developer/Xcode/DerivedData/XXXXXXXXXX-envirswdnpegjccdpxakhoykfnfq/Build/Products/Debug-iphonesimulator/XXXXXXXXXX.app/WMMGDataModel.momd/WMMGDataModel 5.mom'
Command /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/momc failed with exit code 1
The relevant part seems to be:
/Users/AAAAAAA/Desktop/Everything from DT 1:20:15/App projects/WMMG/XXXXXXXXXX/XXXXXXXXXX/WMMGDataModel.xcdatamodeld/WMMGDataModel 5.xcdatamodel:WMMGAccount.attribute: error: WMMGAccount.attribute must have a defined type
I've gone into my xcdatamodel, but can't find any attributes that aren't properly defined by type. One suspicious thing I'm seeing is the reference to WMMGDataModel 5. I'm up to version 8 in my model, and can't even find version 5.
This crash began after a recent automatic migration (using MagicalRecord) in which I added an attribute to one of the entities and then recreated the Managed Object Subclass (yes, the new subclass contains the new, properly defined attribute). I've added attributes before, but this is the first time I've encountered this issue.
I've cleaned the thing, quit and restarted Xcode, still crashes. Anybody have any ideas? I also deleted the DerivedData folder for the project. Still won't build.
Edit:
I just recreated all my managed subclass files. Still no dice--same error message.
Edit:
I tried running another project as a control, and got this message:
Unable to run app in Simulator
An error was encountered while running (Domain = FBSOpenApplicationErrorDomain, Code = 4)
So I quit Xcode and the simulator, restarted Xcode. Same error.
Yet more info
I restarted the computer and tried again, but am still getting "Build Failed" with the same error message.
If anyone else has run into anything like this, I sure would appreciate some guidance here... :)
Final edit
Please see solution in my answer below...
Ok, I finally cured the problem with a decision to delete my xcdatamodeld and rebuild the entire model. Some research into how to do this yielded a less destructive and less risky method in this answer.
Here's hoping it will help someone else with this problem.
Thanks to all who took a look!
I've never had the problem you describe, but have a few suggestions. Apologies if you've already tried these:
First, in the model editor, can you access the model version 5 that you suspect is the problem, eg.:
If it's there, you can hopefully fix the attribute error. If it doesn't appear there, have you tried right-click in the Project Navigator and select "Show in Finder":
Then in Finder looking for the version 5?

Compilation failed for data model at path - xcode 6

In one of my project, I am using CoreData to store all local data and it was working absolutely fine till xcode 5.1.1. But with the upgrade to xcode 6, I started getting compilation error. The error looks like this:
/Users//Desktop/test/test/test.xcdatamodeld: Compilation failed
for data model at path
'/Users//Library/Developer/Xcode/DerivedData/test-bheksmasmjewxsejmxeyasvvhrer/Build/Products/Debug-iphonesimulator/test.app/test.momd/test.mom'
I tried searching SO for the issue, found some suggestions and implemented them in my project as well. But none of the suggestions worked for me and am left wondering "what the h**l this issue is. Any hint/suggestion/solution will be a great help right now.
Thanks
Not sure if you ever resolved this issue, but I had the same issue after I erroneously versioned my data model. I found the steps below fixed my issue:
In Xcode locate your .xcdatamodeld file then click "Show in Finder" and delete the .xcdatamodel file that was not previously visible in Xcode or that was erroneously versioned.
Hope this helps you in some way, if you are still looking for answers.

Data Model Version Compiler (MOMC) Error

Has anyone seen this and know how to fix it?
/Users/venerley/dev/Phase3-Dev-iOS-DB/WTInstrument.3/Persistence/DataBase/WTModel.xcdatamodeld:
Could not create bundle folder for versioned model at
'/Users/venerley/Library/Developer/Xcode/DerivedData/WirelessTouch-gmsbhbucobwnlqcijbkyknnkktuu/Build/Products/Debug-iphoneos/WirelessTouch.app/WTModel.momd'
This problem occurs when building for arm64 devices. Using Xcode Version 5.1 (5B130a) & iOS 7.1.1
not sure if this makes sense to anyone? however this error message turned out to be a red herring.
The problem was due to the use of libCorePlot-CocoaTouch.a not being built for arm64. When this was fixed the database problem disappeared too!
I would be interested to hear from anyone who can explain how/why the libCorePlot-CocoaTouch.a file could interfere with the compilation of the database.
Face the same problem
I just created new model with new name and copy all the entity from old model and paste in new model and deleted old model, it worked

Coredata inferred mapping model is failing on my old databases

I'm using CoreData for one of my databases, and I'm having trouble with an upgrade to my App.
My old databases are no longer loading ... I get the error "Cocoa error 134190" which I believe means that the inferred mapping model is failing.
When I started editing this version of my App, I created a new model version, and I simply added one new attribute to one entity, and two new attributes to another entity. Nothing was changed or deleted.
I've checked inside my App's directory, and all of the model versions are there.
I even have a snapshot of my previous version of the App, and with that snapshot I can load my core data files.
To debug what is going wrong, I took the exact data model from my previous snapshot and used it in my current version, and I still get the error.
I've even done a "diff" on every file in my ".app" directory packages, and there are only two files that are different between the two. One is the actual binary for the application, and the other is the "Info.plist" file. I looked at the Info.plist files, and they too are basically identical (the new one has a newer bundle version, but no other change).
Any idea why the inferred mapping is broken?
I am getting the same error even when the data models are completely unchanged from my last version which works.
This is extremely frustrating.
Any information as to how to track down problems like this in the future would also be greatly appreciated!!!
I found the answer ... the problem was that in my new version, I was rearranging the locations of my files. I did so by simply moving the database to a new location. What I didn't realize is that coredata databases have some knowledge of their path built in, and you can't simply move them.
I needed to change the location of the database using the NSPersistentStoreCoordinator's method:
migratePersistentStore:toURL:options:withType:error:
My fault, but I really wish that core data error messages weren't so cryptic.
In the next version of my App, I'm going to remove core data completely.
Ron
I don't believe core data actually cares where the database file is, but I could be wrong. In the times I have seen this error, specifically "Cocoa error 134190" while trying to infer a model mapping, it's been the case that there was actually a problem trying to migrate to the next version of the model.
For example, when I found this thread today because I was helping someone with this problem, the real underlying issue was that the type of one of the attributes was accidentally changed. The automatic migration can't handle that sort of change.
A somewhat easy way to look at the changes between two model versions is to diff the description files themselves on the command line with diff:
diff yourNameHere.xcdatamodeld/yourNameHere5.xcdatamodel/contents yourNameHere.xcdatamodeld/yourNameHere4.xcdatamodel/contents
(That assumes you have a core data model description named "yourNameHere" and you're looking at a problem migrating from version 4 to 5. You'll have to adjust for your specific files.) In this diff you should see whatever additional things you've added, but you're really looking for something like a type changing when it shouldn't.

Core Data migration failing on Release builds only

I added an attribute to a Core Data model (iOS). I was on version 2, so I added a new model and saved the new attribute under version 3.
My loading code is standard (initializing a MOM using initWithContentsOfURL: pointing at my .momd directory inside my bundle), then passing that MOM to a NSPersistentStoreCoordinator.
Then, I download my app from the App Store, run it, and then try to test the migration. Lightweight migration is working fine on my Simulator and my phone in Debug (tethered to Xcode 4).
However, when I sync a Release build (using the "Archive" feature on Xcode) using iTunes, my app's data store fails to migrate with this error:
Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed.
(Cocoa error 134130.)", reason=Can't find model for source store}
Worse yet, the store gets lost in some voodoo state where it cannot escape - if I re-tether the device and install a Debug build from Xcode again, I can't "recover" the migration.
The error message above omits the details about my entities. I can provide that if helpful, but any ideas on what might be wrong here? I've read just about every question on SO about this error code and so far all of them have failed to produce a result.
I tried a manual migration, but it also yielded an error. However, since I only added 1 attribute to 1 entity, it doesn't make sense that lightweight migration isn't working.
Every time I've seen this problem, in my code or someone else, it has been XCode getting into some kind of bad state with regards to the model versions it deploys in the application. Open the Release IPA archive of your app, and look at what mom files are in it. If you see one of the previous versions missing, that is likely this same problem. As for a solution, I've had mixed results; some variation of the following steps works for me, but never in a consistent order.
Clean & delete the derived data for the project (make sure you have an archive of your released app saved so you can symbolicate if necessary)
Rename the previous model version files (in xcode), adding or removing the space between the name and the digit representing the version number (if it has a space, replace with '_', if it doesn't have a space try adding one)
Add a new version of the model, without changing any of it's content, and make it the 'current' version
I know these steps seem like grasping at straws, which is exactly what it feels like whenever this happens to me. You might consider using one of your support incidents with Apple, it would be nice to know what their official answer to this issue is.

Resources