I create my tables in my SQLiteOpenHelper onCreate() but receive
SQLiteException: no such table
or
SQLiteException: no such column
errors. Why?
Home / DeveloperSection / Forums / When onCreate() and onUpgrade() method run in SQLiteOpenHelper
SQLiteException: no such table
SQLiteException: no such column
Aryan Kumar
27-May-2023In the SQLiteOpenHelper class, the onCreate() and onUpgrade() methods are used to manage the creation and upgrading of an SQLite database. These methods are called in specific scenarios as follows:
onCreate():
onUpgrade():
The SQLiteOpenHelper class manages the database lifecycle and determines when to call the onCreate() and onUpgrade() methods based on the database version provided. It internally keeps track of the database version and compares it with the version specified during instantiation.
When you instantiate an instance of the SQLiteOpenHelper class, you provide a database name, an initial database version, and optionally, an implementation of the onCreate() and onUpgrade() methods. The framework takes care of invoking these methods as needed when you interact with the database using the helper class.
It's worth noting that the onCreate() method is only called once, during the initial creation of the database, while the onUpgrade() method is called whenever the database version is incremented.
Anonymous User
15-Oct-2015SQLiteOpenHelper
onCreate()
andonUpgrade()
callbacks are invoked when the database is actually opened, for example by a call togetWritableDatabase()
. The database is not opened when the database helper object itself is created.PRAGMA user_version