0

I have an app that reads from a sqlite Database. I recently updated the database and wanted to include the new one, so I deleted the old (chose "Move to Trash") and replaced it with the new one. The data still seemed to reflect the old version. I deleted the database again, thinking that should trigger an error when the code to look it up ran:

let path = NSBundle.mainBundle().pathForResource("members", ofType:"sqlite3")

but the app still ran fine (all on my simulator). Is it hiding somewhere that I need to remove a reference from? Is this going to be a problem for my users? It's read-only on their end.

EDIT:

The schema has not changed, this is just some new or updated data. I'm lost.

thumbtackthief
  • 6,093
  • 10
  • 41
  • 87

1 Answers1

2

So, to solve this problem, you need to delete your app from device, than the DB will be deleted also. After that perform full project clean and run application again, it should work fine. But if I understand correctly - you will be changing database sometimes and want for users to see this changes also. For this purposes I would recommend using Parse service: it is simple in use and also free. All needed info you can find here http://parse.com/

Or other solution to use database migrations system :

1) question about migrations : Best practices for in-app database migration for Sqlite

2) library for easy managed migrations : https://github.com/layerhq/FMDBMigrationManager Hope it helps you.

Community
  • 1
  • 1
Volodymyr
  • 1,165
  • 5
  • 16
  • This seems like so much overhead for something so simple. Would I be wrong to just rename my new database and update my code to reflect? – thumbtackthief Jan 24 '16 at 14:44
  • You can update code, but users that use previous version may not update app. If they will download new app version - that may work. But it's not the best solution to force user to update app because of changed data. Forcing updates should be done if something new was added when really is some changes("for example added new mode or some feature"). You need to remember that our users are really lazy and the less they do the better app is. So you should decide on your own. You can also rewrite code for Core Data usage and use theirs migrations - it should be easier than use directly SQLite. – Volodymyr Jan 24 '16 at 14:50
  • Also renaming DB will create new storage on device, but the old one will also be present there. As for me that is wrong approach to do so because you are not changing DB but just creating new one, old DB will take the same amount of storage as before, as that is not good really. – Volodymyr Jan 24 '16 at 14:57
  • I'm totally lost... I don't know Objective C well enough to get any of these to work – thumbtackthief Jan 24 '16 at 19:13
  • I don't understand where my project is getting the data from, since I've deleted the database entirely – thumbtackthief Jan 24 '16 at 19:14