small medium large xlarge

Back to: All Forums  Core Data
Paul54729_pragsmall
17 Jun 2010, 17:31
Paul Johnson (21 posts)

I’m working my way through section 5.4 of the book. I’m getting a “Persistent store migration failed, missing mapping model” error when I run my GrokkingRecipes (v3) program.

I have two questions.

(1) Where can I get more information to debug this issue? I’d like to know what mapping model the program is expecting.

(2) I’m suspecting that the information in my Application Support directory is in a state other that what it was in when I did the earlier migration from version v1 to v2 of GrokkingRecipes, probably through an error of my own. Fortunately I have the whole thing under version control (with Subversion) so I’ll be able to easily return to a previous point in my work and resume from there.

This raises a general question about debugging methodology. It looks to me like a wise approach is to actually include backup copies of the Application Support folder contents as part of the project to make it easier to recover from errors. Does anyone have an opinion on this?

Avatarsmall_pragsmall
18 Jun 2010, 06:30
Marcus S. Zarra (284 posts)

That one is always fun to debug. What that is telling you is that it can’t figure out a way from your source to your destination. There are several things that can cause this:

  • You have no mapping model
  • Your actual source does not match the source in your mapping model
  • Your actual destination does not match the destination in your mapping model

If you turn on core data debug you can hopefully see some more information which will point you in the right direction. I would also check your compiled app and make sure the mapping model is in the Resouces directory where it belongs.

Paul54729_pragsmall
18 Jun 2010, 12:48
Paul Johnson (21 posts)

How do I turn on core data debug? Do I need to download something from Apple?

Avatarsmall_pragsmall
18 Jun 2010, 19:46
Marcus S. Zarra (284 posts)

From the Apple Docs:

Debugging Fetching

With Mac OS X version 10.4.3 and later, you can use the user default com.apple.CoreData.SQLDebug to log to stderr the actual SQL sent to SQLite. (Note that user default names are case sensitive.) For example, you can pass the following as an argument to the application:

-com.apple.CoreData.SQLDebug 1 Higher levels of debug numbers produce more information, although using higher numbers is likely to be of diminishing utility.

The information the output provides can be useful when debugging performance problems—in particular it may tell you when Core Data is performing a large number of small fetches (such as when firing faults individually). Like file I/O, executing many small fetches is expensive compared to executing a single large fetch. For examples of how to correct this situation, see “Faulting Behavior.”

While the docs refer to fetching I have found it tends to spit out information about migration as well and gives us some insight into the issue. I would also check the NSError you are getting back and see if it has any suberrors that contain additional information.

Paul54729_pragsmall
19 Jun 2010, 01:33
Paul Johnson (21 posts)

Thanks. I did find that switch and had tried it but it didn’t do anything. I realize it was because my data file is in XML format (ostensibly so I could debug it). Well, I was certainly fooled as it turns out I might have been wiser to have chosen SQL format to do what you suggest.

I suppose there must be some way to convert between database formats, but I guess I’m just going to step through the creation of each of the GrokkingRecipes versions and forget about why my v2 to v3 migration fails. (In a real application development or application update situation I would need to understand how to debug what I’ve got however.)

Thanks for your reply.

Paul54729_pragsmall
20 Jun 2010, 01:01
Paul Johnson (21 posts)

I was able to solve the problems I was having with my GrokkingRecipes code for version 3 of the data model. It was a problem with incorrect bindings which needed to be changed after the data model was changed. The following switch added to the command line of the executable gave me the very helpful debugging information: -NSBindingDebugLogLevel 1

Generic-user-small
06 Aug 2010, 06:31
Damian Haslam (18 posts)

Admittedly I’m no veteran developer, but this section of the book has brought me undone.

I have no idea how to turn on Core Data debugging and I followed the instructions precisely (as far as anyone can) and yet I get the “Persistent store migration failed, missing mapping model” mentioned above.

I certainly do have a model, so precisely what do I need to do in order to work out why it’s failing?

If I pass the following as an argument to the application: -com.apple.CoreData.SQLDebug 1 I assume that means I need to run it from the command line - I have done that, and no extra information is displayed beyond that which is displayed when that argument is not specified.

Avatarsmall_pragsmall
06 Aug 2010, 18:54
Marcus S. Zarra (284 posts)

The command is passed as a parameter but you don’t run it from the command line. In Xcode you will see a section call Executables. In that section you will see your application. By showing its information (⌘I) you can then add arguments to it. That will give you a hint.

As for the error, that usually means that it cannot find the hashes for the entities that it is looking for. The extra debug information will tell you what it is failing to find.

Generic-user-small
08 Aug 2010, 02:31
Damian Haslam (18 posts)

Thanks Marcus - that makes sense. I assume the extra information is output in the console? I can’t see anything extra to help (unless I’m looking for the wrong thing). There’s no more information now that the argument is specified in Executable “Grokking Recipes” Info under “Arguments to be passed on launch” (-com.apple.CoreData.SQLDebug 1).

In addition, there are a number of errors. First popup says “Persisten store migration failed, missing mapping model.”, second one says “Failed to initialize the store”, and those two messages are displayed twice more (for a total of three times per message). When the final “Ok” button is pressed, the output as per below is displayed:

run
[Switching to process 16646]
Running…
2010-08-08 12:23:09.473 Grokking Recipes[16646:a0f] The contentValues and content bindings need to be bound to the same observable object
2010-08-08 12:23:09.475 Grokking Recipes[16646:a0f] The contentValues and content bindings need to be bound to the same observable object
2010-08-08 12:23:10.283 Grokking Recipes[16646:a0f] An uncaught exception was raised
2010-08-08 12:23:10.284 Grokking Recipes[16646:a0f] Cannot perform operation without a managed object context
2010-08-08 12:23:10.289 Grokking Recipes[16646:a0f] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot perform operation without a managed object context'
*** Call stack at first throw:
(
	0   CoreFoundation                      0x00007fff814f3cc4 __exceptionPreprocess + 180
	1   libobjc.A.dylib                     0x00007fff871690f3 objc_exception_throw + 45
	2   CoreFoundation                      0x00007fff814f3ae7 +[NSException raise:format:arguments:] + 103
	3   CoreFoundation                      0x00007fff814f3a74 +[NSException raise:format:] + 148
	4   AppKit                              0x00007fff81cd9318 -[_NSManagedProxy _managedObjectContext] + 67
	5   AppKit                              0x00007fff81cd928e -[_NSManagedProxy _persistentStoreCoordinator] + 21
	6   AppKit                              0x00007fff81cd920f -[_NSManagedProxy _entity] + 40
	7   AppKit                              0x00007fff81cd937b -[_NSManagedProxy fetchRequestWithSortDescriptors:limit:] + 89
	8   AppKit                              0x00007fff81cd8f90 -[NSObjectController(NSManagedController) _executeFetch:didCommitSuccessfully:actionSender:] + 68
	9   AppKit                              0x00007fff81cd75c9 _NSSendCommitEditingSelector + 61
	10  AppKit                              0x00007fff81cd8f37 -[NSController _controllerEditor:didCommit:contextInfo:] + 199
	11  CoreFoundation                      0x00007fff814c8d2c __invoking___ + 140
	12  CoreFoundation                      0x00007fff814c8bfd -[NSInvocation invoke] + 141
	13  CoreFoundation                      0x00007fff814e4a11 -[NSInvocation invokeWithTarget:] + 49
	14  Foundation                          0x00007fff83e9e428 __NSFireDelayedPerform + 404
	15  CoreFoundation                      0x00007fff81490678 __CFRunLoopRun + 6488
	16  CoreFoundation                      0x00007fff8148e84f CFRunLoopRunSpecific + 575
	17  HIToolbox                           0x00007fff84d5b91a RunCurrentEventLoopInMode + 333
	18  HIToolbox                           0x00007fff84d5b67d ReceiveNextEventCommon + 148
	19  HIToolbox                           0x00007fff84d5b5d8 BlockUntilNextEventMatchingListInMode + 59
	20  AppKit                              0x00007fff81b1529e _DPSNextEvent + 708
	21  AppKit                              0x00007fff81b14bed -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
	22  AppKit                              0x00007fff81d4fed3 -[NSApplication _realDoModalLoop:peek:] + 442
	23  AppKit                              0x00007fff81d4da61 -[NSApplication runModalForWindow:] + 129
	24  AppKit                              0x00007fff81d4af17 -[NSAlert runModal] + 96
	25  AppKit                              0x00007fff81d6cdb7 -[NSApplication(NSErrorPresentation) presentError:] + 154
	26  Grokking Recipes                    0x0000000100001b91 -[Grokking_Recipes_AppDelegate persistentStoreCoordinator] + 934
	27  Grokking Recipes                    0x0000000100001c64 -[Grokking_Recipes_AppDelegate managedObjectContext] + 95
	28  Grokking Recipes                    0x0000000100001dec -[Grokking_Recipes_AppDelegate windowWillReturnUndoManager:] + 42
	29  AppKit                              0x00007fff81c4d504 -[NSWindow _getUndoManager:] + 204
	30  AppKit                              0x00007fff81c9a627 -[NSTextView(NSPrivate) _setFieldEditorUndoManager:] + 747
	31  AppKit                              0x00007fff81c93c2c _NSEditTextCellWithOptions + 3027
	32  AppKit                              0x00007fff81c92dc6 -[NSTextFieldCell _selectOrEdit:inView:target:editor:event:start:end:] + 346
	33  AppKit                              0x00007fff81cd4f3c -[NSSearchFieldCell _selectOrEdit:inView:target:editor:event:start:end:] + 169
	34  AppKit                              0x00007fff81c92c6a -[NSCell selectWithFrame:inView:editor:delegate:start:length:] + 55
	35  AppKit                              0x00007fff81c920a4 -[NSTextField selectText:] + 227
	36  AppKit                              0x00007fff81c91e8d -[NSTextField becomeFirstResponder] + 131
	37  AppKit                              0x00007fff81b0e22a -[NSWindow makeFirstResponder:] + 643
	38  AppKit                              0x00007fff81b0df0a -[NSWindow _selectFirstKeyView] + 679
	39  AppKit                              0x00007fff81b0dc43 -[NSWindow _setUpFirstResponderBeforeBecomingVisible] + 190
	40  AppKit                              0x00007fff81b0cfe7 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 986
	41  AppKit                              0x00007fff81b0cbbe -[NSWindow orderWindow:relativeTo:] + 94
	42  AppKit                              0x00007fff81ad8bbc -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1726
	43  AppKit                              0x00007fff81ad6cd9 loadNib + 226
	44  AppKit                              0x00007fff81ad61e9 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 248
	45  AppKit                              0x00007fff81ad6021 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 326
	46  AppKit                              0x00007fff81ad35a3 NSApplicationMain + 279
	47  Grokking Recipes                    0x000000010000143d main + 33
	48  Grokking Recipes                    0x0000000100001414 start + 52
	49  ???                                 0x0000000000000003 0x0 + 3
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
Avatarsmall_pragsmall
08 Aug 2010, 19:49
Marcus S. Zarra (284 posts)

That is a different error. You need to walk through your code with the debugger to find out what is going on. That is not a migration error at all but something else, outside of Core Data, that is not working correctly.

You must be logged in to comment