I need to create new tables and delete others in my local database, however changing only the database version, it does not work it is not creating the new tables that I need.
In the same way I already tried the onUpgrade but it did not work
Future<Database> get database async{
if( _database != null )return _database;
_database = await initDB();
return _database;
}
initDB()async {
Directory documentDirectory = await getApplicationDocumentsDirectory();
String path = join( documentDirectory.path, 'DB.db' );
var ouDb = await openDatabase(path, version: 2,onCreate: onCreate, onUpgrade: onUpgrade);
return ouDb;
}
FutureOr<void> onCreate(Database db, int version) async {
await db.execute('CREATE TABLE nameTable0...');
db.execute("DROP TABLE IF EXISTS NameTable1");
db.execute("DROP TABLE IF EXISTS NameTable2");
}
FutureOr<void> onUpgrade(Database db, int oldVersion, int newVersion) async{
if (oldVersion < newVersion) {
await db.execute('CREATE TABLE NameTable3 ...');
}
//onCreate(db, newVersion);
}