0

Where does Room store the database and how can I force a rebuild of the DB? I've tried looking for the DB under:

data/data/com.me.myapp/No database directory here data/user/0/com.me.myapp/No database directory here

I want to see exactly what data is in the database using SQLLite so I followed these directions "Access database in Android Studio" but I only see a cache and codecache directory stored there. No database directory.

The reason for wanting to see the DB is that I changed the model to add a few fields, but I can't figure out how to force Room to recreate and repopulate the DB with data. I added breakpoints inside my data generator class; however they don't seem to ever get hit.

Aaron Bar
  • 611
  • 1
  • 7
  • 20
  • I have an app using Room and my databases are written to both the directories stated in the documentation (which you quote above). So I would say that the documentation is correct and your problem may lay elsewhere. – Simon Hutton Feb 21 '18 at 16:25
  • "I can't figure out how to force Room to recreate and repopulate the DB with data" -- create an instance of your `RoomDatabase` subclass, then do something with it. – CommonsWare Feb 21 '18 at 16:41

1 Answers1

1

if you change your entities structure (aka add fields) then in order not to loose data and get the fields added when user updates the current version of the app you need to implement migration . See the docs how to do it. So updating the app version will make your db "rebuild" and not lose data. When I just work with test version I delete app and build it on device again it'll implement the changes in db structure but you'll lose the data.

You should definitively see db files in the directories you named. If you want some other method to debug a database you could use this library git link

Rainmaker
  • 10,294
  • 9
  • 54
  • 89