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

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
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.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • Foreign Key Violation (code 19)
    via by Chie Paliza,
  • SQlite Foreign Key Violation
    via Stack Overflow by Isma9
    ,
  • SQLiteConstraintException dont go inside catch
    via Stack Overflow by Mano
    ,
  • Android SQLite mutiple table input
    via Stack Overflow by newProgrammer
    ,
    • 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.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 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) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

    Users with the same issue

    filipebatista
    filipebatista46 times, last one,
    Unknown User
    Unknown User1 times, last one,
    Hiren Amaliyar
    Hiren Amaliyar1 times, last one,
    Indri Yunita
    Indri Yunita20 times, last one,
    filpgame
    filpgame41 times, last one,
    68 more bugmates