3

I'm getting an exception whilst trying to construct an NSMigrationManager instance. The init method is throwing an NSInternalInconsistencyException with an error message that reads 'Model already contains an entity named -Entity Name-'. I haven't been able to find anything that might help me spot a possible solution.

What I can see is that the entity that is mentioned on the error message inherits from a base entity. I can see that the hashes of these entities (entities inheriting from other entities) are different between the source and destination models even though the only change triggering the migration is that I added a new attribute to another entity. This makes me wonder whether this is an Apple's bug.

Any ideas? Possible workaround?

Stack trace below:
0   CoreFoundation                      0x037081e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x034878e5 objc_exception_throw + 44
2   CoreData                            0x015d01c3 -[NSManagedObjectModel(_NSManagedObjectModelPrivateMethods) _addEntity:] + 307
3   CoreData                            0x015c9228 -[NSManagedObjectModel setEntities:] + 392
4   CoreData                            0x015c88b1 -[NSManagedObjectModel copyWithZone:] + 657
5   libobjc.A.dylib                     0x03499bcd -[NSObject copy] + 41
6   CoreData                            0x015db685 -[NSMigrationManager initWithSourceModel:destinationModel:] + 101
Floern
  • 33,559
  • 24
  • 104
  • 119
lblasa
  • 6,284
  • 4
  • 27
  • 29
  • One dead conversation from 2008 seeming to have the same issue (though no mention of Inheritance) - http://www.cocoabuilder.com/archive/cocoa/195740-core-data-migration-exception.html – BadPirate May 29 '14 at 18:00

1 Answers1

1

If you provide a "merged" source model, it's possible to get this error. The fix is to use a model that includes only the version you are merging from. (See the answer here)

Community
  • 1
  • 1
BadPirate
  • 25,802
  • 10
  • 92
  • 123
  • Thanks, this works. I was expecting the original code to work since is the suggestion made on Apple's documentation. – lblasa Jun 20 '14 at 09:53