views:

216

answers:

1

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?

+3  A: 

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.

Ben Gottlieb
Thanks for guiding me to the right direction, since I have very complex changes on the new version I have gaven up doing the migration, it not worthing doing so because it just was sold few copys only and I have removed it from sale on app store.
owen