room迁移报错
原来数据库中有一张表,又新建一张表,然后room迁移报错
Android room Migration didn’t properly handle:Expected TableInfo columns={不是空} Found TableInfo columns={空}
一开始这里我没写修改内容会报上面的错
static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
}
};
这里需要写上创建表的SQL语句
注意
主键配置 PRIMARY KEY NOT NULL
INTEGER 字段 需要加上 NOT NULL DEFAULT 0
static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS record (articleId TEXT PRIMARY KEY NOT NULL,time INTEGER NOT NULL DEFAULT 0)");
}
};
|