jeudi 21 janvier 2016

SQLite Android Foreign Key

Hi guys I'm having a problem about my sqlite database Im trying to have a database with a foreign key. Now Im having trouble with this error it says that something about the insertion and also an error for the foreign key. Can you help me with this? here is my create table code and insertion code enter code here

    //Collection Create Table
private static final String CREATE_TABLE_COLLECTION = "CREATE TABLE "
        + COLLECTION_TABLE + "(" + COLLECTION_CODE + " TEXT PRIMARY KEY," + CUSTOMER_CODE
        + " TEXT," + TRANSACTION_CODE + " TEXT," + TIN + " TEXT," + OR_NO + " TEXT," + DATE
        + " TEXT," + AMOUNT_DUE + " TEXT," + AMOUNT_PAID + " TEXT," + REMARKS + " TEXT," + STATUS
        + " TEXT,"  + " FOREIGN KEY ("+CUSTOMER_CODE+") REFERENCES "+CUSTOMER_TABLE+" ("+CUSTOMER_CODE+"))";


public void addCollection(String collection_code, String customer_code, String transaction_code,
                          String tin, String or_no, String date, String amount_due, String amount_paid,
                          String remarks, String status) {
    SQLiteDatabase db = this.getWritableDatabase();
    //db.execSQL("PRAGMA foreign_keys=ON;");
    ContentValues values = new ContentValues();
    values.put(COLLECTION_CODE, collection_code);
    values.put(CUSTOMER_CODE, customer_code);
    values.put(TRANSACTION_CODE, transaction_code);
    values.put(TIN, tin);
    values.put(OR_NO, or_no);
    values.put(DATE, date);
    values.put(AMOUNT_DUE, amount_due);
    values.put(AMOUNT_PAID, amount_paid);
    values.put(REMARKS, remarks);
    values.put(STATUS, status);

    //inserting row
    long id = db.insert(COLLECTION_TABLE, null, values);
    db.close();// closing database connection

    Log.d(TAG, "COLLECTION ADDED SUCCESSFULLY" + id);

}

and here is the error

enter image description here

Aucun commentaire:

Enregistrer un commentaire