android.database.sqlite.SQLiteConstraintException

column context_id is not unique (code 19)

Samebug tips1

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.


rafaelrafael

Don't give up yet. Our experts can help. Paste your full stack trace to get a solution.

Solutions on the web209

  • via Stack Overflow by Azam Khan
    ,
  • via GitHub by mrkam
    ,
  • Stack trace

    • android.database.sqlite.SQLiteConstraintException: column context_id is not unique (code 19) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782) 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 bsv.a(SourceFile:445) at bsv.b(SourceFile:420) at bsv.a(SourceFile:370) at bsv.a(SourceFile:147) at bsc.a(SourceFile:157) at bjb.a(SourceFile:64) at bix.run(SourceFile:52) at biv.a(SourceFile:258) at biv.handleMessage(SourceFile:251) at jcq.run(SourceFile:141) at jcy.run(SourceFile:438) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at jhi.run(SourceFile:17) at java.lang.Thread.run(Thread.java:841)

    Write tip

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

    Users with the same issue

    joni1408joni1408
    121 times, last one
    NedGr8NedGr8
    1090 times, last one
    AkshayAkshay
    89 times, last one
    asvidasvid
    37 times, last one
    Unknown visitor
    Unknown visitorOnce,
    68 more bugmates