android.database.sqlite.SQLiteConstraintException

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.

  • Create daily crashes the app
    via GitHub by franzejr
    ,
  • Crash - Saving Daily
    via GitHub by negue
    ,
  • GitHub comment 57#157201848
    via GitHub by franzejr
    ,
  • bug on push
    via GitHub by idelcano
    ,
    • android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: NewMessage.type (code 1555) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:952) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86) at com.raizlabs.android.dbflow.structure.database.AndroidDatabaseStatement.executeInsert(AndroidDatabaseStatement.java:77) at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.insert(ModelSaver.java:110) at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.save(ModelSaver.java:57) at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.save(ModelSaver.java:40) at com.raizlabs.android.dbflow.structure.ModelAdapter.save(ModelAdapter.java:103) at com.raizlabs.android.dbflow.structure.BaseModel.save(BaseModel.java:51) at co.runner.app.util.MessageManager$4.run(MessageManager.java:198) at co.runner.app.utils.ThreadManager$SafeRunnable.run(ThreadManager.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818)

    Users with the same issue

    Hiren AmaliyarHiren Amaliyar
    1 times, last one,
    deallocdealloc
    4 times, last one,
    bayukresnobayukresno
    617 times, last one,
    xaviloxavilo
    1 times, last one,
    jkjk
    2 times, last one,
    68 more bugmates