0
votes

I am currently receiving an error of -

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Invoices''

How this came about:

I set up an Entity and Attributes called 'Friends'. I am successfully using Fetch Request to get and display the data I want. The next stage of development for me was to add another Entity called 'Invoices' with various attributes. I added this to the datamodel and added a new fetch request to reflect this.

I have tried to reset the iPhone simulator, and added a new version, changed current version, and changed back to try and clear the error, but no joy.

The app crashes when it gets to this line of code:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Invoices" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

Any suggestions?

1
FYI - I have not made any relationship between 'Friends' and 'Invoices' entitysSam Parrish
Is your datamodel in a separate app, such as a static library ? Anyway I had this error because the .momd file was not included in the main app bundle. Therefore the context could not be initialized. How do you load your data model ?Leonardo

1 Answers

0
votes

Check your build target to make sure that your are using the model file you think you are using.

Sometimes and old complied .momd file will not be removed from the simulator when you change the model file. Completely deleting the app off the simulator, doing a clean on the project and rebuilding usually fixes the problem.

However, the most common cause of this error is a simple typo e.g. using Invoice for Invoices or vice versa.