mardi 20 octobre 2015

Column does not exist in android sqlite database, leading to errors on insert

I have an application which uses databases to store userdata. One table is constructed with the following constructor:

CREATE TABLE IF NOT EXISTS Polish (ID_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, rating INTEGER, imgPath TEXT, NetID TEXT, comment TEXT, brand TEXT, wear TEXT, owned INTEGER, price INTEGER, colour TEXT, type TEXT, shine TEXT );

However, when I attempt to add to this table, I get the following error:

21:39:00.393 4202-4202/luoja.youcanvas E/SQLiteLog: (1) table Polish has no column named shine
10-20 21:39:00.408 4202-4202/luoja.youcanvas E/SQLiteDatabase: Error inserting colour=Light Blue rating=4 shine=Matte wear=2-5 Days price=1 NetID=null brand=LA girl imgPath=/storage/sdcard0/Pictures/yc_20151020_213803-1414162117.jpg name=Matte turquoise comment= owned=1 type=Nail polish
10-20 21:39:00.408 4202-4202/luoja.youcanvas E/SQLiteDatabase: android.database.sqlite.SQLiteException: table Polish has no column named shine (code 1): , while compiling: INSERT INTO Polish(colour,rating,shine,wear,price,NetID,brand,imgPath,name,comment,owned,type) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)

I've looked online and the constructor seems to be correct, but it seems the "Shine" column is not being created. What could be causing this?

EDIT:

The table is created in this method of the SQLiteHelper:

public void onCreate(SQLiteDatabase db) {
    db.execSQL(Product.CONSTRUCTOR);
    db.execSQL(Blush.CONSTRUCTOR);
    db.execSQL(Bronzer.CONSTRUCTOR);
    db.execSQL(Concealer.CONSTRUCTOR);
    db.execSQL(Contour.CONSTRUCTOR);
    db.execSQL(Eyeliner.CONSTRUCTOR);
    db.execSQL(Highlight.CONSTRUCTOR);
    db.execSQL(LipProduct.CONSTRUCTOR);
    db.execSQL(Mascara.CONSTRUCTOR);
    db.execSQL(Moisturiser.CONSTRUCTOR);
    db.execSQL(Polish.CONSTRUCTOR);
    db.execSQL(Powder.CONSTRUCTOR);
    db.execSQL(Primer.CONSTRUCTOR);
    db.execSQL(Setter.CONSTRUCTOR);
    db.execSQL(EyeShadow.CONSTRUCTOR);
    db.execSQL(Foundation.CONSTRUCTOR);
    db.execSQL(YouList.CONSTRUCTOR_WISH);
    db.execSQL(YouList.CONSTRUCTOR_SHOPPING);
}

And the ContentValues used to write to the database are constructed here:

public ContentValues makeValues() {
    ContentValues values = super.makeValues();
    values.put(COLUMN_COLOUR, colour);
    values.put(COLUMN_TYPE, type);
    values.put(COLUMN_FINISH, finish);
    return values;
}

The COLUMN_FINISH refers to the "shine" column.

Here is the schema:

public static final String COLUMN_COLOUR = Val.KEY_COLOUR;
public static final String COLUMN_TYPE = Val.KEY_SUBTYPE;
public static final String COLUMN_FINISH = Val.KEY_FINISH;
public static final String TABLE = "Polish";
public static final String CONSTRUCTOR = CREATE + TABLE + DEFAULTS + SPACE + COLUMN_COLOUR +
        TEXT + SPACE + COLUMN_TYPE + TEXT + SPACE + COLUMN_FINISH + TEXT + CLOSE;

Here are some of the strings used in the constructor:

public static final String INTEGERKEY = " INTEGER PRIMARY KEY AUTOINCREMENT";
public static final String INTEGER = " INTEGER";
public static final String TEXT =  " TEXT";
public static final String BOOL = "BOOLEAN";
public static final String SPACE = ", ";
public static final String CLOSE = " );";

Aucun commentaire:

Enregistrer un commentaire