开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜