0
votes

I added a new version of my data model and changed one attribute from double to float. Do I really have to create a migration mapping?

So now I'm stuck.

I found the Apple docs about migrating to new data models with NSMappingModels (and XCode 3), but I don't know if it is really necessary if just the type of an attribute has changed.

After updating my app, I got that error msg from persistentStoreCoordinator:

Failed to open persistent store: Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed.

Is there an easy way (howto/tutorial) to migrate, if only attribute types have changed? Deleting the app is no solution, the first version is already deployed.

Thanks, Chris

2

2 Answers

1
votes

According to lighweight migration rules, I don't think you will be able to do this automatically. You will have to create an NSMappingModel, selecting both the old and new versions on it during creation. It will automatically create the migration for all your attributes and relationships, with the exception of the attribute you changed.

For the model containing the attribute you will have to create a subclass of NSEntityMigrationPolicy and tell your NSMappingModel to use it (click the Entity in your NSMappingModel and in the inspector in the right side of your screen set it in the "Custom Policy" field. For that particular attribute create a method in your subclass of NSEntityMigrationPolicy and perform the casting there.

-1
votes

You have to follow the instruction for lightweight migration, described here. (There is also a link to the migration guide.)

It is really easy! In a nutshell:

  • create a new version of your data model,
  • select it as the active one,
  • change the attribute,
  • run.