0

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|
+-----------------------------------------------------------------------------------------------+

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Hector
  • 4,016
  • 21
  • 112
  • 211
  • 5
    You can't have two columns with the same name on the same table in SQL. My guess is that this is a Stetho issue. Try copying the database to your development machine (e.g., use Device File Explorer in Android Studio) and examine it using a desktop SQLite client. – CommonsWare Mar 18 '19 at 10:56
  • 2
    I was having the same issue. Both removing autoGenerate and setting it to false as mentioned below did nothing. I still had a duplicate id field. When I copied the database from the Device File Explorer and viewed it locally, there was only one id field. It must be a Stetho issue. – Michelle Williamson Aug 12 '19 at 22:19

1 Answers1

-5

@PrimaryKey(autoGenerate = true)

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

remove it and try