My data class looks like this
@Entity(tableName = "items") data class Item( @ColumnInfo(name = "name") var name: String = "", @ColumnInfo(name = "room") var room: String = "", @ColumnInfo(name = "quantity") var quantity: String = "", @ColumnInfo(name = "description") var description: String = "", @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") var id: Long = 0 )
Room uses SQLite and SQLite supports NOT NULL columns in its database. I tried annotating columns with @NonNull but it has no effect.
Is there a way to make columns in Room Database not nullable?
In Kotlin, this means that title can never be null. To fix this, you just need to change the Entity class a bit, and allow the fields to be Nullable . val type: Int, val url: String?
We'll use two annotations – @Embedded and @Relation. As I mentioned before – @Embedded allows nested fields to be referenced directly in the SQL queries. @Relation describes relations between two columns. We have to specify the parent column name, entity column name and entity class.
When you use the Room persistence library to store your app's data, you define entities to represent the objects that you want to store. Each entity corresponds to a table in the associated Room database, and each instance of an entity represents a row of data in the corresponding table.
For Java you should annotate with @android.support.annotation.NonNull
DO NOT CONFUSE WITH @io.reactivex.annotations.NonNull
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With