问题
Unhandled Exception: DatabaseException(table UsernameTable has no column named rememberMe (Sqlite code 1): , while compiling: INSERT OR REPLACE INTO UsernameTable (username, rememberMe) VALUES (?, ?), (OS error - 2:No such file or directory)) sql 'INSERT OR REPLACE INTO UsernameTable (username, rememberMe) VALUES (?, ?)' args [term@melfs, 1]}
I upgraded my DB. I added new column to UsernameTable
Table. But It's not working. I have already so many records in this db. I can't drop
So How I do add new column to exisiting db. I used Sqflite
initDb() async {
io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "HelperDatabase.db");
var theDb = await openDatabase(path, version: 4, onCreate: _onCreate, onUpgrade: _onUpgrade);
return theDb;
}
OnUpgrade method.
void _onUpgrade(Database db, int oldVersion, int newVersion)async{
if(oldVersion != 5){
await db.execute("ALTER TABLE UsernameTable ADD COLUMN rememberMe INTEGER DEFAULT 0");
}
}
onCreate method
void _onCreate(Database db, int version) async {
await db.execute("""CREATE TABLE UsernameTable(username STRING)""");
}
来源:https://stackoverflow.com/questions/56323951/onupgrade-sqflite-unhandled-exception-databaseexceptiontable-usernametable-ha