I am working on iCloud syncing function. Data sync using core data. Application is already live and working fine. Now, I have changed the core data structure and wanted to do data migration to support old data. Facing problem to fetch and show old data of live application in current development application.

I have tried following scenarios with three different model versions
1) Live application data model version.
2) V1: Data structure same as Live application
3) V2: Update data structure by adding new field.

V1 Data structure: Entity name : “Parent” Having following fields

name                String
createdAt           Date

V2 Data structure: Add new filed of type attributedString for Parent Entity.

name                String
createdAt           Date
attributedString    NSValueTransformer

I have added one to many relationships,
1) One Parent having more than one Child
2) Each Child belongs to one Parents

For Example

Parent1
    -> Child A - (It becomes Parent for ChildB and ChildC)
        -> Child B
        -> Child C
    -> Child X - (It becomes Parent for Child Y and Child Z)
        -> Child Y
        -> Child Z
Parent2
    ->Child A - (It becomes Parent for Child B)
        ->Child B

Relationship Destination Inverse node Parent nodes nodes Parent node

I have tried

  • Light weight migration. But Its not working. May be due to recursive relationships between same entities.
  • Custom migration approach by subclassing NSEntityMigrationPolicy. Its work between V1 and V2 but somehow not working between Live application and V2 (NSEntityMigrationPolicy method doesn’t call. It suppose to be).
  • Gone through solution mentioned in this link (core data "Can't find model for source store";) but didn’t got it resolved.
0

There are 0 answers