How to make primary key as autoincrement for Room Persistence lib

前端 未结 8 1332
無奈伤痛
無奈伤痛 2020-12-07 11:55

I am creating an Entity (Room Persistence Library) class Food, where I want to make foodId as autoincrement.

@Entity
class Food(var foodName: Str         


        
8条回答
  •  独厮守ぢ
    2020-12-07 12:27

    You need to use the autoGenerate property

    Your primary key annotation should be like this:

    @PrimaryKey(autoGenerate = true)
    

    Reference for PrimaryKey.

提交回复
热议问题