Skip to content Skip to sidebar Skip to footer

Android.database.sqlite.sqliteexception: No Such Column: User_id (code 1 Sqlite_error):

being an Android Studio beginner i tend to get lots and lots of tiny errors i cannot find out, please let me know what I am doing wrong because I've tried all the other answers som

Solution 1:

This issue is probably due to i tend to get lots and lots of tiny errors in conjunction with a common misconception regarding the onCreate method.

The onCreate method automatically runs only once when the database is and has actually been created. It does not run every time the App is run.

As such any changes (corrections included) to the structure (tables and columns) will not be applied if they are coded/actioned within the onCreate method.

When developing the easiest fix is to do one of the following 3:-

  • delete the App's data (deletes the database so onCreate will be called).
  • uninstall the App (deletes the database so onCreate will be called).
  • if the onUpgrade method will drop the table(s) and then call onCreate , to increase the database version number as passed as the 4th parameter to the SQLIteOpenHelper sub-class (aka the DatabaseHelper class).

After doing one of the above, rerun the App.

NOTE any existing data will be lost.

  • If data has to be retained then a fix is more complicated but would be based upon using ALTER TABLE statements.

Post a Comment for "Android.database.sqlite.sqliteexception: No Such Column: User_id (code 1 Sqlite_error):"