Why do Room Tables have duplicate id columns?

492 Views Asked by At

I am investigating the use of Room in my current Android project.

When using com.facebook.stetho:stetho:1.5.1 to check my Sqlite Tables structure and content I have discovered all my tables display with two identical columns of their primary key.

Is this a stetho "feature"?

or have I declared my Room entities incorrectly somehow?

All my Kotlin data model classes follow this pattern:-

@Entity(tableName = "my_table")
data class myDO(@ColumnInfo(name = "title") val title: String,
                          @ColumnInfo(name = "uuid") val uuid: String,
                          @ColumnInfo(name = "something") val something: String,
                          @ColumnInfo(name = "what_ever") val whatEver: String?,
                          @ColumnInfo(name = "misc_data") val miscData: String,
                          @ColumnInfo(name = "liked") val liked: Boolean) {
    @PrimaryKey(autoGenerate = true)
    var myId: Long = 0
}

Stetho displays this table as follows:-

+-----------------------------------------------------------------------------------------------+
|Column|Name|myId|myId|title|uuid|something|what_ever |misc_data|liked|
+-----------------------------------------------------------------------------------------------+

1

There are 1 best solutions below

0
On

@PrimaryKey(autoGenerate = true)

Since you have given autoGenerate = true it will create myId twice and have same value

remove it and try