【发布时间】:2021-12-02 13:08:54
【问题描述】:
我正在尝试向我的表中添加新属性,如下所示:
@Entity(
tableName = "invoices", indices = [Index(value = [...], unique = true)]
)
data class Invoice(
...
override val created_at: Long = 0,
override var approved_at: Long? = 0,
) : ICD
所以我创建了以下迁移:
val MIGRATION_3_4 = object: Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE invoices ADD COLUMN created_at INTEGER NOT NULL DEFAULT 0")
database.execSQL("ALTER TABLE invoices ADD COLUMN approved_at INTEGER DEFAULT 0 ")
}
}
但每当我尝试运行时,它都会说迁移没有正确处理并按预期显示:
TableInfo{name='invoices', columns={... ,created_at=Column{name='created_at', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, approved_at=Column{name='approved_at', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0, defaultValue='null'}}, ... }
这是什么发现:
TableInfo{name='invoices', columns={... ,created_at=Column{name='created_at', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='0'}, approved_at=Column{name='approved_at', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0, defaultValue='0'}}, ... }
谁能告诉我为什么它期望默认值 null 吗?
【问题讨论】:
标签: android sqlite kotlin android-room