'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name

surabhi picture surabhi · Nov 23, 2010 · Viewed 7.4k times · Source

I have a window based applicaiton with tab bar and navigation bar integrated into it. On the navigation bar have a custom button which opens a table view.

On clicking on the cell of the table I want to open a new table view controller. But as soon as I click on the cell of first table I get an exception that

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

I have checked that AddForm is in right place.

I have tried all the solutions given above and on other thread, but still stuck. I hope someone can help me.

The flow is something like this

ListButton (on click opens a list view) -> a table view opens -> (on click of a cell should open a new table view Controller and fetch data from core data)

My root view controller code is in the second table view controller file... is that what I am doing wrong? I am doing so because I don't need the core data before that....

Please help

Thanks in advance

Answer

Alex picture Alex · Nov 1, 2011

I Used to have the same problem first of all check in your AppDelegate.m class if the managedObjectContext is created

if it is created check if it is pass it as argument something like this

 MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
    controller.managedObjectContext = self.managedObjectContext;

if that is correct for you main view just be sure that you are passing it through your views something like this

self.detailViewController.managedObjectContext = self.managedObjectContext;

well at least that works for me =)