1

I have an iphone app that has a sqlite db, mapped to core data. All the data manipulation in the app is via Coredata.

On one table I wanted to add a string attribute. And I did two things both with similar crashes:

  1. I tried to use Mesasql to alter the structure. I easily added a Varchar column. But it crashes.

  2. On a separate attempt, with the mapped SQLlite db, restored, I tried adding a attribute to the entity in core data and it crashed.

This is the error I got: * Terminating app due to uncaught exception of class 'NSCFString' terminate called after throwing an instance of 'NSCFString'

So, how can I alter the structure of the sqlite table mapped to core data without breaking the app? Am I fogetting to do a commit or something like that?

Please help

jason
  • 5,391
  • 6
  • 23
  • 26

1 Answers1

1

Every time you modify an entity you have to delete the sqlite store. If your application has already shipped, the alternative is to migrate your data. This SO answer offers a simple explanation of how to do that.

Community
  • 1
  • 1
David
  • 7,310
  • 6
  • 41
  • 63
  • so i have to delete the sqllite db and Xcode will recreate it? – jason Mar 13 '11 at 04:30
  • Yes, it will be recreated when you launch the app again. – David Mar 13 '11 at 12:26
  • ok, I created a migration directory and then created a migration named.1. I modified the data model and entity classes to reflect the two new attributes. I deleted the sqllite DB within xcode (it had asked me if I only wanted to erase the references). I then re-ran, and super crash, plus it does not recreate the sqlite DB. Ideas of what might be happening? – jason Mar 13 '11 at 13:24
  • The Core Data schema for SQLite is undocumented. If you edit the file directly, there is an excellent chance you will corrupt it. Delete the file and start over. – TechZen Mar 13 '11 at 19:21
  • TechZen, delete the SQLite DB or the core data model file? – jason Mar 13 '11 at 21:12
  • Definitely the SQLite DB. I think it should be located here: `~/Library/Application Support/iPhone Simulator/User/Applications//Documents/.sqlite`. Also, can you post the crash log? – David Mar 14 '11 at 00:15
  • I delete both the one in the app directory in my map and on the iphone and nothing works. I think the app is missing the core data creation functions..... – jason Mar 14 '11 at 23:24
  • can you post your appdelegate code, i.e. any core data relevant code? – David Mar 16 '11 at 00:03