androiddatabasefts3fts4

"SQLiteException error: No such table" if I change the table's name in the same DB and run again the app


I have created a fts database DATABASE_NAME and a table FTS_VIRTUAL_TABLE.

I can insert and select values.

If I change the name of the table in my code e.g. FTS_VIRTUAL_TABLE_NEW keeping the same database DATABASE_NAME and run the application I get a SQLiteException error: No such table: FTS_VIRTUAL_TABLE_NEW. I wonder, why, since in onCreate method the proper SQL statement exists. Shouldn't the FTS_VIRTUAL_TABLE_NEW have been created?

However if I change not only the name of the table but also the name of the database (i.e. new database) everything works. The app runs normally (of course with no values in the database initially).

I don't understand why I can't only change the name of the table keeping the same database.


Solution

  • If you change your database schema at all, you need to increment your database version used in your SQLiteOpenHelper constructor and handle upgrades (i.e. drop and recreate or modify tables) in the onUpgrade method.