如何使用房间自动迁移 delete/rename 多列
How to delete/rename multiple columns with Room Auto-Migration
注意:房间自动迁移处于测试阶段 - 2.4.0-beta02
我删除了两个不同表中的两列。我试着重复 @DeleteColumn
注释,像这样
@DeleteColumn(tableName = "User", columnName = "phone")
@DeleteColumn(tableName = "Product", columnName = "description")
@DeleteTable(tableName = "Category")
class TestRoomAutoMigration: AutoMigrationSpec { }
但是我收到这个错误
Repeatable annotations with non-SOURCE retention are not yet supported
问题
- 如果我不能使用自动迁移重复注释,如何delete/rename多列
Kotlin 尚未添加对具有与 Java 相同语法的可重复注释的完全支持。所以我们必须使用容器注解,像这样:
@DeleteColumn.Entries(
DeleteColumn(tableName = "User", columnName = "phone"),
DeleteColumn(tableName = "Product", columnName = "description"),
)
@DeleteTable(tableName = "Category")
class TestRoomAutoMigration: AutoMigrationSpec { }
这也适用于重命名列。
这首先在 Google 问题跟踪器上得到了回答 - link
Kotlin 现在在 1.6 版本中支持可重复注释
org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0
注意:房间自动迁移处于测试阶段 - 2.4.0-beta02
我删除了两个不同表中的两列。我试着重复 @DeleteColumn
注释,像这样
@DeleteColumn(tableName = "User", columnName = "phone")
@DeleteColumn(tableName = "Product", columnName = "description")
@DeleteTable(tableName = "Category")
class TestRoomAutoMigration: AutoMigrationSpec { }
但是我收到这个错误
Repeatable annotations with non-SOURCE retention are not yet supported
问题
- 如果我不能使用自动迁移重复注释,如何delete/rename多列
Kotlin 尚未添加对具有与 Java 相同语法的可重复注释的完全支持。所以我们必须使用容器注解,像这样:
@DeleteColumn.Entries(
DeleteColumn(tableName = "User", columnName = "phone"),
DeleteColumn(tableName = "Product", columnName = "description"),
)
@DeleteTable(tableName = "Category")
class TestRoomAutoMigration: AutoMigrationSpec { }
这也适用于重命名列。
这首先在 Google 问题跟踪器上得到了回答 - link
Kotlin 现在在 1.6 版本中支持可重复注释
org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0