No results (empty array) on fetching entity after lightweight migration

I have used lightweight migration and there are no errors in loading the new store but when i fetch an entity i get an empty array. What could be the reason?

there is something worth considering. The old store had an entity A which had a relationship with entity B and C, both or which are no longer included in the new model. Just incase such a thing could be a issue.

Thanks. Neerav

Replies

Possible cause is that Xcode needs to be able to map old model on new model. So preparation is critical.

Is it the first time you experience the problem ? Did previous lightweight migrations work OK. These links may help (I don't know how much practice of Core Data migration you have)

https://developer.apple.com/documentation/coredata/using_lightweight_migration

h t t p s : / / w w w.raywenderlich.com/7585-lightweight-migrations-in-core-data-tutorial

Hope that helps.

  • This is the first time I am using lightweight migration and I am facing this issue. The returned array is empty. There are no errors.

  • _inferredMappingModelForSourceModel:destinationModel:error:; _ This method looks helpful. I can check in advance if the model can infer the new model. I need to make an NSURL to the path of the models in the project folder.

    @"file:///Users/neeravkothari/Current Project/Expenses Pro v2/Expenses Pro/Expenses Pro/Model/Core Data/Expenses.xcdatamodeld/Expenses.xcdatamodel";

    @"file:///Users/neeravkothari/Current Project/Expenses Pro v2/Expenses Pro/Expenses Pro/Model/Core Data/Expenses.xcdatamodeld/Expenses 2.xcdatamodel";

    **Failed to load model as no file exists at path ** What is wrong with the path name?

  • Alight I checked the NSURL is loading file. Its in the next step that the code throws the error... when using initWithContentsOfURL method of the NSManagedObjectModel class. Further I get message (zero byte file) which i checked through Finder, isn't true.

Add a Comment