android.database.sqlite.SQLiteConstraintException: Foreign Key Violation (code 19)

Searched on Google with the first line of a JAVA stack trace?

We can recommend more relevant solutions and speed up debugging when you paste your entire stack trace with the exception message. Try a sample exception.

Recommended solutions based on your search

Samebug tips

,
Expert tip

activity.OnCreate is executed every time the app launches or the screen is rotated, so, putting your DB initialization inside it will cause the DB to be called too many times causing the exception. Try to use the MyDatabase.onCreate method for this.

Solutions on the web

via Google Groups by Chie Paliza, 1 year ago
Foreign Key Violation (code 19)
via GitHub by xtj-9182
, 1 year ago
UNIQUE constraint failed: capitulos.path (code 2067)
via Stack Overflow by hashim
, 1 year ago
UNIQUE constraint failed: context.context_id (code 2067)
via Stack Overflow by Alexia White
, 1 year ago
UNIQUE constraint failed: context.context_id (code 2067)
via Stack Overflow by Tony
, 11 months ago
PRIMARY KEY must be unique (code 19)
via Stack Overflow by seon
, 9 months ago
UNIQUE constraint failed: bookmark.Id (code 1555)
android.database.sqlite.SQLiteConstraintException: Foreign Key Violation (code 19)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
at com.example.maecea.ipon2.DataBaseHandler.addallowance(DataBaseHandler.java:143)
at com.example.maecea.ipon2.TypeWeekly.OnProceedMonthlyClick(TypeWeekly.java:40)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

Users with the same issue

8 times, 1 year ago
Samebug visitor profile picture
Unknown user
Once, 1 year ago
46 times, 4 months ago
12 times, 1 year ago
1165 times, 1 year ago
72 more bugmates

Know the solutions? Share your knowledge to help other developers to debug faster.