这是我遇到的错误,
java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
at android.arch.persistence.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:135)
at android.arch.persistence.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:115)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:151)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:411)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:96)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:100)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:233)
我的数据库类是
@Database(entities = SliderImageModel.class, version = DbConfig.Version_SliderImage_84, exportSchema = false)
public abstract class SliderImageDatabase extends RoomDatabase {
public abstract SliderImageDao sliderImageDao();
public static SliderImageDatabase INSTANCE;
private static final Migration MIGRATION_1_84 = new Migration(DbConfig.Version_NewsAnnouncement_1, DbConfig.Version_SliderImage_84) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL(SLIDERIMAGE);
}
};
private static final Migration MIGRATION_2_84 = new Migration(DbConfig.Version_SchoolEvent_2, DbConfig.Version_SliderImage_84) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL(SLIDERIMAGE);
}
};
答案 0 :(得分:-1)
尝试通过增加版本号来尝试以下操作,
@Database(entities = pojo.class, exportSchema= false, version=2 )