views:

29

answers:

1

I'm having an extremely annoying problem with Core Data in the iPhone SDK. I would say in general Core Data for the most part appears easy to use and nice to implement.

I have a sqlite database that is being used as a read only reference to pull data elements out for an iPhone app. It would seem there are really mysterious issues relating to what seems to be migration of the database to the most recent versions of my schema.

Why can't you just clean out your stored objects and models and let a project redo all of it when you compile next? You would think if you setup a stored object model there would be a way to just reset it and recompile. I've tried what feels like a thousand 'tips' that have been the results of hours of google searches and documentation prowling to figure out how to do this.

My most recent error during compile time is below.

2010-04-07 18:23:51.891 PE[1962:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't merge models with two different entities named 'PElement''

All of this code has been working in the simulator and is only causing me troubles now because I made a change to the schema. I also have the database options for automatically migrating set as below.

NSMutableDictionary *optionsDictionary = [NSMutableDictionary dictionary];
[optionsDictionary setObject:[NSNumber numberWithBool:YES] 
    forKey:NSMigratePersistentStoresAutomaticallyOption];

[optionsDictionary setObject:[NSNumber numberWithBool:YES]
    forKey:NSInferMappingModelAutomaticallyOption];
A: 

Clean your project. Xcode does not delete the old compiled mom file out of the bundle when you start versioning. Cleaning the project before your next build will resolve this issue.

Marcus S. Zarra
See this is what I would think as well. But I had such issues with it working that I ended up duplicating the table in my .sqlite db and changed the name of my model object. Everything started working. Only problem it when you compile it is still looking for the old object. If you remove the old db table from the sql db then you get errors. Even if I clean it. I can't figure out what would still be referencing the old table structure. Something seems to hang out after a clean still.
Hazmit
Then your project structure is incorrect. You should only have the xcdatamodeld checked as to be compiled and not the xcdatamodel files. Also, the xcdatamodel files should be inside of the xcdatamodeld
Marcus S. Zarra