OnUpgrade SQFLITE: Unhandled Exception: DatabaseException(table UsernameTable has no column named rememberMe (Sqlite code 1):

独自空忆成欢 提交于 2019-12-11 16:16:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!