MBN
MBN

Reputation: 304

App is getting crashed after updating from appstore becuase of Coredata migration

My app is working perfect for the first release v1.

In second release v2, i made a mistake while doing coredata migration - I accidentally given a renaming ID for an entity (It was empty before) in my coredata. Becuase of that the app was crashing when updating, but it is working when freshly downloading v2 version.

Now, what should i do in my next release v3, to fix this crash?

If i am replacing the renaming ID of the entity to empty, updating an app from v1 -> v2 -> v3 will be working.

But if a user freshly downloaded v2, it will get crashed again.

Please give me some workaround for this issue. Thanks in advance.

Upvotes: 0

Views: 254

Answers (1)

Uma_Shanker_Tiwari
Uma_Shanker_Tiwari

Reputation: 463

Use core data Lightweight Migration. Lightweight migration is especially convenient during early stages of application development, when you may be changing your managed object model frequently, but you don’t want to have to keep regenerating test data. You can migrate existing data without having to create a custom mapping model for every model version used to create a store that would need to be migrated.

Core Data Must Be Able to Infer the Mapping

To perform automatic lightweight migration, Core Data needs to be able to find the source and destination managed object models itself at runtime. Core Data looks for models in the bundles returned by NSBundle’s allBundles and allFrameworks methods. If you store your models elsewhere, you must follow the steps described in Use a Migration Manager if Models Cannot Be Found Automatically . Core Data must then analyze the schema changes to persistent entities and properties and generate an inferred mapping model.

For Core Data to be able to generate an inferred mapping model, changes must fit an obvious migration pattern, for example:

  • Simple addition of a new attribute
  • Removal of an attribute
  • A non-optional attribute becoming optional
  • An optional attribute becoming non-optional, and defining a default value
  • Renaming an entity or property

Source : https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweightMigration.html

Upvotes: 1

Related Questions