简体   繁体   English

房间数据库中的DEFAULT值(Kotlin)

[英]DEFAULT values in Room database (Kotlin)

I am trying to migrate from existing Loaders/Content Providers to Room. 我正在尝试从现有的Loaders / Content Providers迁移到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. 在Kotlin中添加默认值,例如var columnName: Int = 0但是当我检查RoomDatabase_Impl它会忽略模式创建中的Kotlin默认值。 How to introduce DEFAULT values for columns with Room? 如何为Room引入DEFAULT值?

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. 经过一些研究后,我认为Room没有提供一种方法来生成带有“ColumnName DEFAULT 1”SQL的数据库模式,该数据库将在数据库级别上。 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. 我认为它假定只通过实体访问db,如果你想使用加载器使用实体和原始查询,那么你必须在所有加载器中添加默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM