DEFAULT values in Room database (Kotlin)

Viewed 2455

I am trying to migrate from existing Loaders/Content Providers to Room. I need some columns to have default values. Adding defaults in Kotlin, like var columnName: Int = 0 but when I check RoomDatabase_Impl it ignores the Kotlin Defaults in schema creation. How to introduce DEFAULT values for columns with Room?

1 Answers

After some research I think Room does not provide a way to generate db schema with "ColumnName DEFAULT 1" SQL which would be on db level. I think it assumes that db is accessed only through Entities and if you want to use Entities and raw queries using loaders then you would have to add the default values in all loaders.

Related