0

I know this question gets asked a lot and I have looked through all the answers and cant seem to fix the error. I am just trying to do a simple select all from one of my tables but I am getting an error saying no such table ingredient (code 1). I have used the same syntax in the create statement as two other tables that I know work so I dont know where I have gone wrong.

Any guidance will be greate

Create Statement

//Ingredient create statement
private static final String CREATE_TABLE_INGREDIENTS = "CREATE TABLE "
        + INGREDIENTS_TABLE + "("
        + KEY_ID + " INTEGER PRIMARY KEY AUTO INCREMENT,"
        + KEY_RECIPE_CODE + " INTEGER AUTO INCREMENT, "
        + KEY_INGREDIENT_NAME + " TEXT,"
        + " FOREIGN KEY ("+KEY_RECIPE_CODE+") REFERENCES " +RECIPE_TABLE+"("+KEY_CODE+"));";

Ingredient Column Names

//Ingredient column names
public static final String KEY_RECIPE_CODE ="reciep_code";
public static final String KEY_INGREDIENT_NAME ="ingredient_name";
public static final String KEY_MEASUREMENT = "measurement";

Select all function

public Cursor possibleRecipes()
{
    return db.query(INGREDIENTS_TABLE, new String[]{KEY_ID, KEY_CONTENTS_NAME}, null, null, null, null, null);
}

Calling the function from the class

    Cursor cursor = adapter.possibleRecipes();
Hayes121
  • 283
  • 7
  • 25
  • Nope no special characters, I have updated the question showing the column names I am using. I added the table from the creation of the database and have un installed the app and reinstalled it again to make sure the table does get created – Hayes121 Dec 08 '15 at 15:27
  • I assume the table `INGREDIENTS_TABLE` has a value of `"ingredients"`. Or does it? – Phantômaxx Dec 08 '15 at 15:58
  • Sorry yes it does, `private static final String INGREDIENTS_TABLE = "ingredients";` is the string I am using – Hayes121 Dec 08 '15 at 16:02
  • 1
    This seems like a typo, to me: `public static final String KEY_RECIPE_CODE ="reciep_code";` I mean `reciep` should be `recipe` – Phantômaxx Dec 08 '15 at 16:04
  • 1
    Very well spotted, that fixed it thank you so much! I had been staring at it for too long and thought the spelling was right! – Hayes121 Dec 08 '15 at 16:10

0 Answers0