Core Data Migration - Can't find mapping model for migration
Asked Answered
W

4

9

I followed the guide found here: http://www.timisted.net/blog/archive/core-data-migration/ but keep getting "Can't find mapping model for migration" when I start up the app with the new model. I've tried it in xcode 3 and xcode 4, multiple times, but can never get it to work.

Currently my options are set to:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
    [NSNumber numberWithBool:NO], NSInferMappingModelAutomaticallyOption,
    nil];

I had YES set for the infer option before but then it was just migrating without calling my custom policies that I need to migrate, which I assume is cause it couldn't find the mapping model before either.

Any reason my mapping models aren't getting picked up? I've double checked that no changes were made to the previous model by checking it against the SVN version of it.

Thanks.

Wellspring answered 20/3, 2011 at 16:45 Comment(0)
W
8

Turns out the Mapping Model needs to be part of the .xcdatamodeld package, which is impossible to do within xcode 4. With it in there, it works great.

Note: my mapping file stopped working again, and I found that it was 0KB on disc, so I had to recreate it again and it worked fine after that. I quickly committed it and will see if it disappears again. The problem is that Xcode 4 indexes it or something so it looks fine in xcode but on the file system its empty.

See my comment below for the reason (xcode 4's mapc (map compiler) is broken).

** THIS HAS BEEN FIXED IN THE NEWER XCODEs/SDKs.**

Wellspring answered 21/3, 2011 at 18:9 Comment(6)
There are still a few rough edges in xcode 4, and I think we just found another one, glad you got it working though.Thousand
Actually, I also found that it stopped working again after a bit, and the file turned out to be 0KB, so I think xcode 4 corrupts the file but keeps it indexed or something so the fact that its empty isn't shown in xcode itself, but visible in finder. Very annoying but now that i know to look for that it will be quick to fix in the future. Thanks for all the help yesterday.Wellspring
Ddid you ever find a better solution to this problem? I've had it happen a couple of times now. Opening and building in xc3 sometimes fixes it, but I think that this is a side effect of the build cycle not fixing my xcode 4 project.Grope
Yes, I've figured it out. Here is my bug report to apple (which they duped as a known problem): We have two models with a mapping model used for migration. When compiling and running the app from Xcode 3, the migration works as expected. Moving to xcode 4 with the same models/mapping model gives us a "Can't find mapping model for migration" error. Taking the mapc from the xcode 3 usr/bin/ and copied it to the xcode 4 usr/bin (after backing up the xcode 4 one) and rebuilding in xcode 4 allows the migration to go forward as expected.Wellspring
This doesn't seem to be working for me, any other ideas as to what might be causing this?Marcosmarcotte
Yeah, this problem has been fixed. I guess I'll mention it in my answer.Wellspring
U
4

I had a similar problem:

Custom Policy in my xcmappingmodel will not be executed

in my case it was not executed since my migration did not do any changes to the tables - maybe this is your problem too.

Unwise answered 27/6, 2011 at 12:33 Comment(0)
W
2

Make sure to set up the source data model as your OLD version, and the destination as the new one... I have gotten the error above when these were backwards.

Wold answered 6/5, 2011 at 22:40 Comment(0)
T
0

you need to create a new version of the schema, as opposed to changing the current version. presuming you have done this, what changes have been made to the model? some changes are too drastic to be inferred reliably.

Thousand answered 20/3, 2011 at 22:3 Comment(11)
Yes, my model is versioned and I have created a new version. Like I said in my post, I'm using a mapping model and custom policies, not trying to infer it. The problem is that it's not finding the mapping model for some reason.Wellspring
excuse me, I misread the code, would you be able to post a screenshot of your mapping model?Thousand
I'm not sure that would be useful since they're not being used. The log says "Can't find mapping model for migration". I've checked and the mapping model does have the right versions selected. By the way, what is the proper way to test this. I've been installing it from an old workspace with the old version of the model and then using a new workspace to simulate the upgrade. This seems to work when i tell it to infer the model so I assume its ok.Wellspring
It was to make sure that you had the correct old model and new model selected, (both MOMs need to be included in the build) I usually use the old build to generate the data, and then overwrite the app with the new build.Thousand
does the log say anything else?Thousand
sourceModel: {()} destinationModel: {()} same model: NO equivalent model: NO reason: Can't find mapping model for migrationWellspring
sourceModel.versionIdentifiers destinationModel.versionIdentifiers is what was used to print the first 2. Then a == and equal call. And the last piece is the reason.Wellspring
I didn't print the entire user info but that one is very long with a ton of stuff about my model which isn't useful.Wellspring
have you added both models and the mapping model to the copy phase of the build? if thats there, you have set the keys as youve listed, and you are migrating in the right direction, then it should be working...Thousand
I don't have any of the core data stuff in the Copy area, but all of it is in the Compile Sources area. Should it also be in the Copy Bundle Resources area?Wellspring
I got it working by going back to xcode 3 and making sure the Model Mapping was part of the .xcdatamodeld package. I had it in there before but I guess something else was wrong then. Thanks anyways for the help.Wellspring

© 2022 - 2024 — McMap. All rights reserved.