0

I was working in android studio in an app that passes the user's info to a table using SQLite. It was working but I needed to add another data so according to me I convert the table to another of 4 columns but in the logcat appears this message

"E/SQLiteLog: (1) table STUDENTS has 3 columns but 4 values were supplied"

and this is what I have:

public class SQLiteDb extends SQLiteOpenHelper {

    private static final String TABLE_STUDENTS="CREATE TABLE STUDENTS(NAMES TEXT, 
    LASTNAMES TEXT, ID TEXT, IMAGE TEXT)";

    public SQLiteDb(Context context) {
        super(context, "db_students", null, 1);
    }
}

Does anyone know how can I fix it to accept 4 values?

Jaymin
  • 2,879
  • 3
  • 19
  • 35
user129270
  • 11
  • 5
  • Remove the old Student table exist with 3 columns and then create the new student table. – Jaymin May 30 '19 at 04:44
  • update table using alter table query and add one more column to it – primo May 30 '19 at 04:47
  • Yeah jaja but how I create the table with 4 columns? **Sorry for my ignorance, i'm learning :s – user129270 May 30 '19 at 04:48
  • Your code seems to be incomplete, do you mind adding some more piece of code. So that the questions like: - Where have You created the **STUDENTS** table previously? - How are you trying to insert the value ? - What is existing Db contains? will be clear. And if you are just trying to manipulate with the existing table , try to alter(help) the existing table which is having 3 columns ,to 4 columns then try inserting the 4 values, hope you won't get any error. Thanks – Abhishek May 30 '19 at 04:47
  • Abhishek Thanks for your help. I´m gonna check that. – user129270 May 30 '19 at 05:03
  • below link will help you with SQLite : https://stackoverflow.com/questions/48627459/sqlite-with-android-studio/48636533#48636533 – Mitesh Machhoya May 30 '19 at 05:09

1 Answers1

0

The typical reason why columns don't appear to exist is the mis-conception about the Database Helper's onCreate method and that it is assumed that it runs every time the App is run. In fact it will only run automatically once when the database is first created (once created the database remains).

Hence it is likely that you have changed the table to have an additional column after the database has been created.

The fix is simple either delete's the App's data or uninstall the App, after doing one then rerun the App and the new schema will be applied and you will have the four columns.

MikeT
  • 51,415
  • 16
  • 49
  • 68