Flutter - Modify Sqlite table without deleting database Flutter - Modify Sqlite table without deleting database flutter flutter

Flutter - Modify Sqlite table without deleting database


Well I managed to resolve my issue. With some help from dlohani comment and How to add new Column to Android SQLite Database link.

I created a new method "_onUpgrade" and call it as parameter of "openDatabase" and changed the version number.Following is my relevant code:

initDb() async {    Directory documentDirectory = await getApplicationDocumentsDirectory();    String path = join(documentDirectory.path, 'maindb.db');    var ourDb = await openDatabase(path, version: 2, onCreate: _onCreate, onUpgrade: _onUpgrade);    return ourDb;  }  // UPGRADE DATABASE TABLES  void _onUpgrade(Database db, int oldVersion, int newVersion) {    if (oldVersion < newVersion) {      db.execute("ALTER TABLE tabEmployee ADD COLUMN newCol TEXT;");    }  }