简体   繁体   中英

Core Data : What will happen if the previous version of 'xcdatamodel' is missed?

We're developing an app using Core Data.

First, the app had a file named MyApp_001.xcdatamodel , and users have installed it.

Then, we create two branches based on MyApp_001 : MyApp_002 & MyApp_003 .

Now, MyApp_002 has two model version : MyApp_001.xcdatamodel & MyApp_002.xcdatamodel , and the current version is MyApp_002.xcdatamodel , which has some modification on MyApp_001.xcdatamodel .

MyApp_003 has two model version : MyApp_001.xcdatamodel & MyApp_003.xcdatamodel , and the current version is MyApp_003.xcdatamodel , which also has some modification on MyApp_001.xcdatamodel .

What confuses me is : some users have installed MyApp_002 first,
Consider that MyApp_003 doesn't contain the model file MyApp_002.xcdatamodel , when they upgrade the app to MyApp_003 , there might be some problem?

How Core Data migrates the data indeed?

Thanks!

To migrate data to a new model, the old model must be present.

When migrating a data store from one model to a new model, Core Data needs to be able to open the data store. That means you need the model that the store uses-- either the one that created it or, if you've previously migrated to a new model, the model used in the most recent migration. If that model is not present, migration is impossible.

In your case, if users installing version 3 might be upgrading from version 2, then the version 2 model must be present. It's the only way to open a data store that was created with that model.

It doesn't matter that a newer model is based on a specific older model. The fact that version 2 and version 3 are both based on version 1 is completely irrelevant. All that matters for migration is the difference between the current model and the one the data store uses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM