When i deploy my app to Emulator in Android the DB will also get deployed. If i do any changes to DB it will not get deployed again to Emulator. To do this, everytime i have to delete the Emulator from device manager and create new one. This process is really annoying, any idea of how to delete the DB from Emulator and deploy new one.
6 Answers
you just need to increase the version of the data base which you provide in constructor or the class extending the SQLIteOpenHelper......
and override onUpgrade in SQLIteOpenHelper :
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion > oldVersion)
Log.v("Database Upgrade", "Database version higher than old.");
myContext.deleteDatabase(DB_NAME);
}
Comments
one more way if u want to delete database just drop table and again recreate table again as shown below where
String Droptable="drop table if exists item_master"; // where item_master is table name
myDataBase.execSQL(Droptable);
after dropping it recreate it as
String Createtable="CREATE TABLE \"item_master\" (\"item_id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , \"item_name\" VARCHAR, \"item_img\" VARCHAR, \"item_s_desc\" TEXT, \"item_desc\" TEXT, \"item_map\" VARCHAR, \"bookmark\" VARCHAR DEFAULT N, \"category_id\" INTEGER)";
myDataBase.execSQL(Createtable);
you can chnage column name or add or remove column according to ur requirement
Comments
Rather than deleting emulator delete the database from
ddms----> file explorer ----> data/data/your_package_name--->databases --->yourdatabase .
and delete it.
and you can do one more thing
simply uninstall the application and install it again , this will remove the database and shall create the database again.