如何删除下一版本的房间数据库 android.DROp或删除不工作的列.? @Database(entities = {User.class, AdTime.class}, version = 1, exportSchema = false) public abstract class AppDataBase extends RoomDatabase { private static
@Database(entities = {User.class, AdTime.class}, version = 1, exportSchema = false) public abstract class AppDataBase extends RoomDatabase { private static AppDataBase INSTANCE; public abstract UserDao userModel(); public abstract AdDao adModel(); public static AppDataBase getInMemoryDatabase(Context context) { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context, AppDataBase.class, "adrider") // To simplify the codelab, allow queries on the main thread. // Don't do this on a real app! See PersistenceBasicSample for an example. .allowMainThreadQueries() // .addMigrations(MIGRATION_1_2) // .fallbackToDestructiveMigration() .build(); } return INSTANCE; } static final Migration MIGRATION_1_2=new Migration(1,2) { @Override public void migrate(@NonNull SupportSQLiteDatabase database) { database.execSQL("ALTER TABLE User " + "DROP Download"); } }; }原则应该仍然相同,因为您在Room下使用SQLite.因此,您应该能够发出该链接中描述的相同SQL语句.你有没有尝试过?
database.execSQL("CREATE TABLE t1_backup AS SELECT a, b FROM t1"); database.execSQL("DROP TABLE t1"); database.execSQL("ALTER TABLE t1_backup RENAME TO t1");
显然,更改表名称和列名称以适合您的方案.