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.

  • GitHub comment 209#229767013
    via GitHub by dabx
  • GitHub comment 199#227340450
    via GitHub by danysz
  • Android sqlite ID not generated
    via Stack Overflow by Sadragos
  • sqlite: Android sqlite ID not generated
    via by Unknown author,
  • Create daily crashes the app
    via GitHub by franzejr
  • Crash - Saving Daily
    via GitHub by negue
  • GitHub comment 57#157201848
    via GitHub by franzejr
    • io.requery.sql.StatementExecutionException: Exception executing statement: insert into Event (code, colour, dayName, endTime, name, roomCode, roomDescription, staff, startTime, studentOwner, type, weeks) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) at io.requery.sql.EntityUpdateOperation$1.evaluate( at io.requery.sql.EntityUpdateOperation$1.evaluate( at io.requery.query.BaseScalar.value( at io.requery.sql.EntityWriter.insert( at io.requery.sql.EntityWriter.cascadeWrite( at io.requery.sql.EntityWriter.updateInverseAssociation( at io.requery.sql.EntityWriter.updateAssociations( at io.requery.sql.EntityWriter.insert( at io.requery.sql.EntityWriter.insert( at io.requery.sql.EntityDataStore.insert( at io.requery.sql.EntityDataStore.insert( at io.requery.rx.SingleEntityStoreFromBlocking$1.get( at at at rx.Single$ at rx.Single$ at rx.Single.subscribe( at rx.Single.subscribe( at rx.Single$19$ at at rx.internal.schedulers.ExecutorScheduler$ at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at Caused by: java.sql.SQLIntegrityConstraintViolationException: android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787) at at at io.requery.sql.EntityUpdateOperation$1.evaluate( ... 23 more Caused by: android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId( at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId( at android.database.sqlite.SQLiteStatement.executeInsert( at ... 24 more

    Users with the same issue

    4 times, last one,
    2 times, last one,
    Hiren AmaliyarHiren Amaliyar
    1 times, last one,
    617 times, last one,
    1 times, last one,
    68 more bugmates