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)""");
}
oldVersion
andnewVersion
(_onUpgrade
). I guess query inonUpgrade
is not being called. – NecessarianinitDB()
.. – Vitusversion
inopenDatabase()
to5
or higher. Your DB seems to get wrong condition. – Necessarianprint()
statement to _onUpgrade()
method. It's not printing – VitusopenDatabase
. In this case,onUpgrade
will not be called. You can debug your db explained in this doc. github.com/tekartik/sqflite/blob/master/sqflite/doc/dev_tips.md – Necessarian