Room persistent library reset version to 1
Is there any ways to reset room library version to 1. I tried uninstall the app on my phone. It is not working.
Downgrading versions using Room only works if you completly remove the app.
You can either do that via adb (adb uninstall your.app.package) which removes your databases aswell, or you delete the data/cache in your app-overview using your device.
There's actually a faster way, if you're okay with loosing your data. But I guess above option is no better in that sense.
When you build your database you have to set .fallbackToDestructiveMigration()
like in the following example.
database = Room
.databaseBuilder(getApplicationContext(), ActionsDatabase.class, "database.db")
.allowMainThreadQueries()
.fallbackToDestructiveMigration()
.build();
This way every time you change you database version the database gets rebuild. You can also change your version number back and forth, so going from 1 to 2 and back to 1, if you like.
I found the simple solution to reset the Room DataBase to Version 1.
In my application i will have a Test.db sqlite file which i have Created intially using SQL ite browser.
When i need to Reset the Room Database to Version 1. I will Create a New DataBase(Test.db )file in the SQL ite Browser making all required changes needed. And paste the Database file in the Asset folder. Keeping the Version to 1.
This worked for me.