问题
I use Core Data and lightweight migration for my iPhone app.
Suppose I have created 3 versions of the data model for the app. One user installed the early version of my app and its data model version is still v1. When the user update the app to the latest version which has the data model version v1,v2 and v3, what happened during the update?
The sqlite database migrate from v1 to v2 first and then migrate from v2 to v3? Or it just jump from v1 to v3?
回答1:
Internally, I believe Core Data lightweight migration will apply the changes to each subsequent version in order, but for your purposes you can think of it as a migration that happens directly to the final version. To my knowledge there are no "hooks" to intercept and run code between versions during a lightweight migration.
If you need to alter data or add new data, you should determine the model version dynamically and react accordingly.
回答2:
Core Data doesn't care about the order of versions and it doesn't care about any intermediate versions. It just knows the source version and target version, it will migrate directly between these.
Generally with lightweight migrations this will work fine though.
来源:https://stackoverflow.com/questions/19592423/how-many-migration-steps-does-core-data-lightweight-migration-have