-1

I am getting the error shown below and have seen other questions on this but none of the solutions seem to fix my issue. i

I create the table within the OnCreate function, I originally included foreign keys but commented them out as I thought that was the issue. I have created other tables using the same format and it has worked. any idea of why this table wont create like the rest?

@Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("PRAGMA foreign_keys=ON");
        db.execSQL("CREATE TABLE IF NOT EXISTS user (username VARCHAR PRIMARY KEY, password VARCHAR, firstName VARCHAR, surname VARCHAR, email VARCHAR)"); //Create table is not there.
        db.execSQL("CREATE TABLE IF NOT EXISTS exercise (exerciseID VARCHAR PRIMARY KEY, exerciseName VARCHAR, muscleGroup VARCHAR, equipmentType VARCHAR)");
        db.execSQL("CREATE TABLE IF NOT EXISTS workout (exerciseNameID VARCHAR,userID VARCHAR, date VARCHAR PRIMARY KEY, repRange INTEGER, weightKG INTEGER)");
//        db.execSQL("create table " + TABLE_WORKOUT + " (COL_userID VARCHAR, COL_exerciseIDFK VARCHAR,COL_date date,COL_repRange INTEGER,COL_weightKG INTEGER)");
//        FOREIGN KEY (COL_exerciseIDFK) REFERENCES " +TABLE_EXERCISE+" (exerciseID), FOREIGN KEY (COL_userID) REFERENCES " +TABLE_USER+ " (username))"

Method of inserting:

public void addWorkout(String exerciseNameID,String userID, String date, int repRange, int weightKG)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put(COL_exerciseIDFK, exerciseNameID);
        values.put(COL_userID, userID);
        values.put(COL_date, date);
        values.put(COL_repRange, repRange);
        values.put(COL_weightKG, weightKG);

        //inserting rows
        db.insert(TABLE_WORKOUT, null, values);

        db.close();
    }

This method is identical to another which works fine.

Any responses are greatly appreciated.

D Jones
  • 55
  • 11
  • Do not post images of error messages but paste the **text** into the question. – sticky bit Feb 01 '20 at 12:19
  • Uninstall the app and rerun so the database is recreated. – forpas Feb 01 '20 at 12:38
  • 2 Tips, if you are having problems with tables not existing try deleting the database files, this can be done with Device Explorer as `onCreate` is only run if the database file does not exist. Also you can copy the database files to your computer with Device Explorer and then use program like https://sqlitebrowser.org/ to look at the tables easily and test out SQL commands – Andrew Feb 01 '20 at 12:40

1 Answers1

0

@forpas commented the answer to my issue, I had to reinstall the application.

Detailed method for answer here:How to reinstall

D Jones
  • 55
  • 11