room数据库升级

static final Migration MIGRATION_1_2 = new Migration(1, 2) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            database.execSQL("CREATE TABLE IF NOT EXISTS `UsersMessage` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `time` INTEGER NOT NULL, `noReadCount` INTEGER NOT NULL, `from_id` INTEGER NOT NULL, `to_id` INTEGER NOT NULL, `headUrl` TEXT, `formName` TEXT, `content` TEXT)");
            // 创建新添加的表,可以将room自动生成的SQL拷贝过来

INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
        InfoDataBase.class, "message").addMigrations(MIGRATION_1_2)
        .build();






你可能感兴趣的:(room数据库升级)