Making Changes to Data Model with SQLite iOS
I'm reading data from a pre-populated sqlite database using CoreData. Everything is fine and dandy, except when I decide that I want to add another entity to the CoreData model (and another table to the sqlite database). I've tried several things, including making the changes to the model in Xcode, removing the sqlite database, and then hoping it generates a new database like it has in the past.
However no matter what I've tried, I get this error:
The model used to open the store is incompatible with the one used to create the store.
Maybe I'm not doing this the right way, but it seems like Xcode makes it difficult to change the data model, which doesn't make se开发者_如何学Gonse to me when you're developing an app.
In general, if you delete your app and recreate it, the boilerplate code that comes with the project will generate you a new (and like you say, compatible) database.
Also, CoreData is intended to be used as an object graph with persistence; what it does with the generated SQLite DB as a result of providing this is its own business.
If what you're saying is: 'I have a valid CoreData store file and model, and I'm trying to hand-upgrade the store file to match a new model', you're breaking the rules of the framework. To morph an incompatible store to a new model, you need to use versioning and mapping models (without directly touching the SQLite DB).
精彩评论