Room cannot verify the data integrity

前端 未结 20 2349
一向
一向 2020-12-04 11:43

I am getting this error while running program with Room Database

Room cannot verify the data integrity. Looks like you\'ve changed schema but forgot to updat         


        
20条回答
  •  隐瞒了意图╮
    2020-12-04 12:13

    By default Android manifest have android:allowBackup="true", Which allow apps to persist their SQLite DB on reinstallation.

    Suppose your DATABASE_VERSION was initially 3 and then you decide to reduce DB version from 3 to 1.

    @Database(entities = {CallRecording.class}, version = DATABASE_VERSION)
    public abstract class AppDatabase extends RoomDatabase {
        public abstract RecordingDAO recordingDAO();
    
    //    static final Migration MIGRATION_1_2 = new Migration(1, 2) {
    //        @Override
    //        public void migrate(SupportSQLiteDatabase database) {
    //            // Since we didn't alter the table, there's nothing else to do here.
    //        }
    //    };
    }
    

    You can achieve it like this

    • Clear App data from Setting. This will remove older DB(DATABASE_VERSION =3)from phone
    • Uninstall your App
    • Reduce DATABASE_VERSION version to 1
    • Build and Reinstall Your App

    Its a good practise to keep DATABASE_VERSION as constant.

提交回复
热议问题