I have an issue with a core data migration that is failing in way I don't understand.
I have a migration path from an old version of the data model that looks something like this:
- v1 - initial model
- v2 - requires light weight migration
- v3 - requires light weight migration
- v4 - requires custom migration
- v5 - light weight migration
I am putting together an integration test to run the migrations from v1 - current. I wrote a small helper that can query the current store, and given a model, run the proper type of migration. This more or less has worked, but I've run into an error on the custom migration step that I don't conceptually understand.
I am using NSMigrationManager::migrateStoreFromURL which has the following description:
Migrates of the store at the specified source URL to the store at the destination URL, performing all of the mappings in the mapping model. A store must exist at the source URL; if a store does not exist at the destination URL, one will be created (otherwise the migration will append to the existing store.) Invoking this method will perform compatibility checks on the source and destination models (and the mapping model.) If an error occurs during the validation or migration, this method will return NO.
The test case copies in a v1 sqlite store and successfully auto migrates to v3, and then fails at the custom migration with this error:
NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)"
UserInfo=0x210d740 {metadata={ NSPersistenceFrameworkVersion = 419; NSStoreModelVersionHashes = { lots of hashes that would be noise in this post...}; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "0D2C0907-5F60-4EED-A61B-E726EEB0DA68"; "_NSAutoVacuumLevel" = 2; }, reason=The model used to open the store is incompatible with the one used to create the store
So, just to recap, I only have the source store, which has been auto migrated up to v3. I don't have a destination store, I was hoping to rely on NSMigrationManager to create the destination store. It doesn't make sense to me that the migration would fail due to a model mismatch with a store that doesn't exist. Any ideas?
Just for extra context, when debuggging, I have verified that I am passing in the proper instances of all parameters to the method. The source and destination models have been loaded, the mapping model used for the custom migration was loaded from the test bundle by querying with the source and destination models (a promising result, as this will fail if you have anything wrong), and the URL's for the sqlite stores look right.