Caused by: android.database.sqlite.SQLiteConstraintException:
NOT NULL
constraint failed: (code 1299 SQLITE_CONSTRAINT_NOTNULL)
You might come across this error when you are using Room
database on Android. This happens because the generated schema for your tables mark some of the table’s columns as NOT NULL
.
For example, if you Entity
class looks like this:
@Entity(tableName = "books")
data class Book(
@PrimaryKey
val id: Int,
val title: String,
val description: String,
val info: String,
val type: Int,
val url: String
)
The generated columns title
description
info
url
NOT NULL
SQLiteConstraintException
val title: String
In Kotlin, this means thattitle
can never be null.
To fix this, you just need to change the Entity
class a bit, and allow the fields to be Nullable
.
@Entity(tableName = "books")
data class Book(
@PrimaryKey
val id: Int,
val title: String?,
val description: String?,
val info: String?,
val type: Int,
val url: String?
)
Thanks, man really great Stuff