Previous data disappeared due to CoreData app version upgrade.

Asked 2 years ago, Updated 2 years ago, 36 views


All data disappears (or is stored internally but is no longer visible) when the version is upgraded. I made a terrible mistake.

I don't even know the cause.
I am not fiddling with the data model even when upgrading.

Currently,
as a candidate for the cause I'm thinking about ·As it is written in the book - (NSPersistentStoreCoordinator*) persistentStoreCoordinator
At the bottom of the , click [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
I left it as it says
·Because I didn't do the migration process

There is no confirmation regarding the two.I couldn't find a similar example when I googled.
Basically, AppDelegate is not fiddling with it, and everything except candidate 1 is as initial as it should be.

-(NSPersistentStoreCoordinator*) persistentStoreCoordinator{
    // approximately

    if(![ persistentStoreCoordinator addPersistentStoreWithType: NSSQLiteStoreType 
                            configuration:nil URL:storeUrl 
                            options:nil error:&error]) {
        [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]; // Add
        NSLog(@"Unresolved error%@,%@", error, [error userInfo]);
        abort();
    }    

    return persistentStoreCoordinator;
}

I'm really sorry to all the users, and if you can recover the data,
I would appreciate it if you could tell me how to do that.

If you don't get the data back, please let me know how to deal with it so that it won't happen next time.
It's helpful.

ios

2022-09-30 20:45

1 Answers

Now I know the cause.

It was written here, but all the causes are still
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
It seems that it was a group of .
This will delete the data.sqlite file, so when updating,
to take over the data. I don't think so.

Thank you all for your reply.


2022-09-30 20:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.