How can I get information about the column caused foreign key constraint in android sqlite? How can I get information about the column caused foreign key constraint in android sqlite? android android

How can I get information about the column caused foreign key constraint in android sqlite?


I think you can find the answer in the following qestion:

Possible to get specific error details from Android SQLiteConstraintException?

Look at solution 2 posted by antoino.


No direct way to find column name that violate the foreign key constraint from SQLiteConstraintException: foreign key constraint exception.

But you can find operation(delete, insert, create etc) name that raise SQLiteConstraintException: foreign key constraint exception.In following log

 04-27 11:15:27.152: E/AndroidRuntime(22031): FATAL EXCEPTION: main    04-27 11:15:27.152: E/AndroidRuntime(22031): android.database.sqlite.SQLiteConstraintException:               foreign key constraint failed (code 19)    04-27 11:15:27.152: E/AndroidRuntime(22031):    at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)    04-27 11:15:27.152: E/AndroidRuntime(22031):    at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:727)    04-27 11:15:27.152: E/AndroidRuntime(22031):    at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)    04-27 11:15:27.152: E/AndroidRuntime(22031):    at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)    04-27 11:15:27.152: E/AndroidRuntime(22031):    at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1494)    04-27 11:15:27.152: E/AndroidRuntime(22031):    at it.jackpot21.personalmoney.DbAdapter.SQLdelete(DbAdapter.java:89)    04-27 11:15:27.152: E/AndroidRuntime(22031):    at it.jackpot21.personalmoney.PersoneActivity$5.onClick(PersoneActivity.java:215)

In the above log

04-27 11:15:27.152: E/AndroidRuntime(22031): at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1494)

this tells us delete operation raise exception. Then you can find which line in your code raise this exception and check your query and column manually.


Newer SQLite versions add the table names to the error message, but in neither case do you get the column names.