Room can't find boolean column when it exists

3841 views android

I've trying to build a Dao using an entity that has a boolean value, room keeps saying that the column doesn't exists even when it exists.


@Entity(tableName = "device_table")
data class Device(
    var name: String,
    var strength: Int,
    @ColumnInfo(name = "pk")
    @PrimaryKey(autoGenerate = false)
    var address: String,
    @ColumnInfo(name = "created_at")
    var createdAt: String,
    var synchronized: Boolean
) {
    constructor() : this("", 0, "", "", true)


interface DeviceDao {
     * Inserts a device into the database, if it already exists
     * the device gets updated with the device data.
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOrUpdate(device: Device)

     * Retrieves all the bluetooth devices from the
     * local database ordered by their creation date.
    @Query("SELECT * FROM device_table ORDER BY created_at ASC")
    fun read(): LiveData<List<Device>>

    @Query("SELECT * FROM device_table WHERE synchronized = 0 ORDER BY created_at ASC")
    fun readUnSync(): List<Device>

     * Nukes the device_table, deletes everything.
    @Query("DELETE FROM device_table")
    fun deleteAll()

Room using SQL completion using Android Studio finds the synchronized column just fine, but when I try to run the app, this appears:

There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such column: synchronized)

public abstract java.util.List<> readUnSync();

The column exists, I don't know whats happening, Im even using the boolean value as an Int because SQLite doesn't have Boolean values

answered question

1 Answer


you are missing annotation @ColumnInfo(name = "synchronized") ...

while using Java & SQL keywords as column names tends to be confusing.

posted this

Have an answer?


Please login first before posting an answer.