android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: awards.key (code 1299)

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.

  • Android database method was called twice
    via Stack Overflow by user4901016
    ,
  • Database crash
    via GitHub by gsczechowski
    ,
    • android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: awards.key (code 1299) 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:1471) at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341) at com.thebluealliance.androidclient.database.ModelTable.add(ModelTable.java:44) at com.thebluealliance.androidclient.database.ModelTable.add(ModelTable.java:69) at com.thebluealliance.androidclient.database.writers.AwardListWriter.write(AwardListWriter.java:23) at com.thebluealliance.androidclient.gcm.notifications.AwardsPostedNotification.updateDataLocally(AwardsPostedNotification.java:120) at com.thebluealliance.androidclient.gcm.GCMMessageHandler.handleMessage(GCMMessageHandler.java:199) at com.thebluealliance.androidclient.gcm.GCMMessageHandler.onHandleIntent(GCMMessageHandler.java:127) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.os.HandlerThread.run(HandlerThread.java:61)

    Users with the same issue

    mhicauber
    mhicauber3 times, last one,
    lribeiro
    lribeiro4 times, last one,
    Ajeet
    Ajeet9 times, last one,
    Stefan Braune
    Stefan Braune9 times, last one,
    Bassiuz
    Bassiuz1 times, last one,
    68 more bugmates