ios-add column to sqlite after apply lightweight migration?

297 views Asked by At

I am developing an app that use Core Data and SQLite. The SQLite database is for retrieve data. I filled the SQLite database with data, and thereafter I used lightweight migration to add some new attribute to my entities.

Now I have changed the SQLite file with sqlitebrowser and added new column to it (for a new attribute that has been added to the data model) and filled columns with some data. But this new column shows nothing when I fetch data.

I have not had an error when I ran the project; but how can I alter the SQLite file? Do I have to alter the SQLite file manually?

my app work perfectly before lightweight migration .my question look like this :link but i do lightweight migration correctly. my app like iPhoneCoreDataRecipes by apple sample code. i use pre-filled sqlite database in my app.how i can change sqlite db? i know each entity is model is table is sqlite db and each attribute is table's column in sqlite? i manualy add new column to sqlite file (ZNOTE ) and fill it.but it show nothing when i fetch from sqlite.

1

There are 1 answers

1
Tom Harrington On

If you are using Core Data, you cannot modify the SQLite schema by editing the SQLite file and expect it to work. You must add new properties by using the Core Data model editor in Xcode. When the app runs, all that Core Data knows about your SQLite file is what the model file tells it. If you have modified the schema but not the model file, Core Data won't know about your changes and may corrupt your data or crash the app.

Core Data is not a wrapper around SQLite; it uses a very different API, and SQLite is an implementation detail that you should mostly not care about.

If you're unfamiliar with how to change the Core Data model, take a look at Apple's Core Data Model Versioning and Data Migration.