Q: Android SQLite : constraint failed error code 19 I have execute the following sql:
update record set out_payment=4 where out_payment=4;
the out_payment of record is defined as Integer and reference the Payment(id)
I can ensure the 4 was the one of the ID of the payment table;
but I still got the constrained failed....
07-31 10:20:36.014: ERROR/Database(19085): Error updating out_payment=4 using UPDATE record_table SET out_payment=? WHERE out_payment = 4
07-31 10:20:45.964: ERROR/AndroidRuntime(19085): FATAL EXCEPTION: main
07-31 10:20:45.964: ERROR/AndroidRuntime(19085): android.database.sqlite.SQLiteConstraintException:   error code 19: constraint failed

the code is as following:
values.clear();
values.put(RecordSchema.ID_OUT_PAYMENT, oldid);
selection = RecordSchema.ID_OUT_PAYMENT + " = " + oldid + "";
this.db.update(Table.RECORD, values, selection, null);

the Schema is as following :
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE.RECORD
+ " (" + RecordSchema.ID + " INTEGER PRIMARY KEY"
+ "," + RecordSchema.AMOUNT + " TEXT NOT NULL"
+ "," + RecordSchema.ID_CATEGORY + " INTEGER NOT NULL"
+ "," + RecordSchema.ID_SUBCATEGORY + " INTEGER"
+ "," + RecordSchema.DATE + " DATE NOT NULL"
+ "," + RecordSchema.ID_IN_PAYMENT + " INTEGER"
+ "," + RecordSchema.ID_OUT_PAYMENT + " INTEGER"

+ ",FOREIGN KEY(" + RecordSchema.ID_CATEGORY + ") REFERENCES " 
+ IsAiZanTable.CATEGORY + "(" + CategorySchema.ID + ") ON UPDATE CASCADE"

+ ",FOREIGN KEY(" + RecordSchema.ID_SUBCATEGORY + ") REFERENCES "
+ IsAiZanTable.SUBCATEGORY + "(" + SubcategorySchema.ID + ") ON UPDATE CASCADE"

+ ",FOREIGN KEY(" + RecordSchema.ID_IN_PAYMENT + ") REFERENCES "
+ IsAiZanTable.PAYMENT + "(" + PaymentSchema.ID + ") ON UPDATE CASCADE"

+ ",FOREIGN KEY(" + RecordSchema.ID_OUT_PAYMENT + ") REFERENCES "
+ IsAiZanTable.PAYMENT + "(" + PaymentSchema.ID + ") ON UPDATE CASCADE"
                + ");");

db.execSQL("CREATE TABLE IF NOT EXISTS " +Table.PAYMENT
+ " (" + PaymentSchema.ID + " INTEGER PRIMARY KEY"
+ "," + PaymentSchema.KIND + " INTEGER NOT NULL"
+ "," + PaymentSchema.NAME + " TEXT NOT NULL UNIQUE"
+ "," + PaymentSchema.TOTAL + " TEXT NOT NULL"
+ "," + PaymentSchema.HIDDEN + " INTEGER NOT NULL"
+ ");");

Any body can help me to solve this problem?
Actually I want to update the id from 4 to 5
I can ensure both 4 and 5 are the exist IDs of the payment table.
But the same problem occurred, so I update 4 to 4 is the same.
I think if I can solve the problem of 4 to 4  , I should solve the problem of 4 to 5 .
Many thanks for your answer!!

A: I have found the answer.
One of my team run the following
db.execSQL("PRAGMA foreign_keys = OFF;");

then put the 0 into the ID_OUT_PAYMENT of record table .
The 0 is not the exist id of the PAYMENT table.
So when I update the ID_OUT_PAYMENT it will trigger the constraint failed.
So If I want to make my sql above run successfully.
I need to run the sql too.
 db.execSQL("PRAGMA foreign_keys = OFF;");

Thanks very much for every one to reply me!!
Thanks!
