title: NOT NULL constraint failed(code 1299 SQLITE_CONSTRAINT_NOTNULL)
body: <p>I have following table in Room database :</p>
  <pre><code>@Entity(tableName = &quot;goals&quot;)
  class SavingsGoalWrapper(
      @PrimaryKey val primaryKey: String = &quot;primaryKey&quot;,
      @SerializedName(&quot;savingsGoals&quot;)
      val wrapper: List&lt;SavingsGoal&gt;
  )
  
  @Parcelize
  data class SavingsGoal(
      @SerializedName(&quot;goalImageURL&quot;)
      val imageUrl: String,
      val targetAmount: Float?,
      val currentBalance: Float,
      val name: String, 
      val id: Int
  ) : Parcelable
  </code></pre>
  <p>Here is how I get data from db :</p>
  <pre><code>override fun getSavingsGoals(): Observable&lt;SavingsGoalWrapper&gt; =
          Observable.create { subscriber -&gt;
              val goals = goalsDao.getGoals()
              if (goals == null) {
                  subscriber.onError(NoDataException())
              } else {
                  subscriber.onNext(goals)
              }
          }
  </code></pre>
  <p>And here is my Dao class :</p>
  <pre><code>@Dao
  interface GoalsDao {
  
      @Query(&quot;SELECT * FROM Goals&quot;) fun getGoals(): SavingsGoalWrapper?
  }
  </code></pre>
  <p>When I run the app, I receive following exception :</p>
  <pre><code>2021-06-01 01:28:36.051 25286-25286/com.sample.android.qapital E/BaseViewModel$sendRequest: android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: goals.primaryKey (code 1299 SQLITE_CONSTRAINT_NOTNULL)
          at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
          at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:938)
          at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790)
          at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:88)
          at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
          at androidx.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.java:64)
          at com.sample.android.qapital.data.source.local.GoalsDao_Impl$2.call(GoalsDao_Impl.java:60)
          at com.sample.android.qapital.data.source.local.GoalsDao_Impl$2.call(GoalsDao_Impl.java:55)
          at io.reactivex.internal.operators.completable.CompletableFromCallable.subscribeActual(CompletableFromCallable.java:36)
          at io.reactivex.Completable.subscribe(Completable.java:2309)
          at io.reactivex.internal.operators.mixed.CompletableAndThenObservable.subscribeActual(CompletableAndThenObservable.java:45)
          at io.reactivex.Observable.subscribe(Observable.java:12267)
          at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.subscribeInner(ObservableFlatMap.java:165)
          at io.reactivex.internal.operators.observable.ObservableFlatMap$MergeObserver.onNext(ObservableFlatMap.java:139)
          at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:51)
          at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:37)
          at retrofit2.adapter.rxjava2.CallEnqueueObservable$CallCallback.onResponse(CallEnqueueObservable.java:60)
          at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:129)
          at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
          at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
          at java.lang.Thread.run(Thread.java:923)
  </code></pre>
  <p>As you see above in says : <code>NOT NULL constraint failed: goals.primaryKey (code 1299 SQLITE_CONSTRAINT_NOTNULL)</code></p>
  <p>How can I resolve this?</p>
  <p>Full source code can be found : <a href="https://github.com/AliRezaeiii/SavingGoals-Cache" rel="nofollow noreferrer">https://github.com/AliRezaeiii/SavingGoals-Cache</a></p>