Avatar ·

How to make auto-increment primary key in Room (Kotlin)?

Hello everyone! I'm a beginner in Android development with Kotlin and I'm using Room for local data storage. I have an Entity for users: ```kotlin @Entity(tableName = "users") data class User( @PrimaryKey val id: Int, val name: String, val age: Int ) ``` I want the `id` field to automatically increment when inserting a new record (like AUTOINCREMENT in SQLite). But when I try to insert a user without specifying an id, Room throws an error because id is a required (non-null) field. I tried making id nullable: ```kotlin @PrimaryKey val id: Int? = null ``` But then Room complains that the primary key cannot be nullable. I also tried the `@NonNull` annotation, but that doesn't help. How do I properly configure auto-increment? Do I need to change the data type?