0

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.

Community
  • 1
  • 1
  • Hi Mehdi - could you add a little bit more detail to your question about how exactly it is going wrong? For example, how are you attempting to fetch the data - and how have you confirmed with sqlitebrowser that you have successfully added the new column? – Vince Bowdren Aug 18 '16 at 09:28
  • Ok .Thanks for helping Vince.my app work perfectly before lightweight migration .my question look like this :http://stackoverflow.com/questions/29918219/ios-application-coredata-with-persistentstore-as-static-sqlite-data-migration 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 column in sqlite? i manualy add new column to sqlite file (ZNOTE ). – Mehdi Negahban Aug 18 '16 at 09:37
  • Hi Mehdi - it's good that you have more information to clarify your question. But it's best if you edit your question to include that new information; that way, any new readers will be able to understand what you are asking without having to also read the comments underneath. – Vince Bowdren Aug 18 '16 at 09:37

1 Answers1

0

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.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • ok tom.i get the point.but what happen to my current sqlite file. should i fill it again.becase it contain many table,1000 row ,image file,and .....export and import doesn't work perfectly? – Mehdi Negahban Aug 19 '16 at 14:58