简体   繁体   中英

iPhone application update (using Core Data on Sqlite)

I have an app which is using Core Data on Sqlite, Now I have a update which has some DB structure changes say adding a new table

I know when an app get updated, it updates the app binary only, nothing on document directory will be changed.

When the app gets updated and launchs at the first time and run

[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

It will find the difference between the data model and DB structure in Sqlite and will throw an exception and quit.

Error: "The model used to open the store is incompatible with the one used to create the store"

So, can anyone here give me some idea how to update an app when there is a DB structure change?

I think we can run a DB script to create that new table when it launchs the update at the first time.

But if there are other changes like changing the type of some fields or deleting some fields, and we need to migrate the old data, this is really a headache. In this case, Is the only way to do is creating a new app?

Is there anyone tried something similar like this?

You need to version your data model to handle any new fields you've added. Apple has detailed documentation on this. If you're just adding fields, it's pretty easy. I haven't tried deleting fields, but I imagine it's also straightforward. Once you get into changing fields, you introduce a little complexity, but it's not too hard.

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