Room cannot verify the data integrity –

  • Post author:
  • Post category:World Tech

Development issue/problem:

I get this error when I run a program with the room database.

The chamber cannot check the integrity of the data. Looks like you changed the schedule, but forgot to update the version number.
You can easily fix this by increasing the version number.

Looks like we need to update the database version, but from where in the room can we do that?

How can I solve this problem?

Solution 1:

If this is the first time you see this message, you are probably working with an unpublished version of the database. If this is the case, it is probably not necessary to upgrade the database version. A simple cleanup of the application data brings you back to the former exception.

If you do not enlarge the database (recommended) :

You need to delete the application data in the Android settings. You can also uninstall the previous version of the application and then install the new version to skip the exception. The latter approach does not work under certain conditions (e.g. when backups are enabled).

Because deleting application data always works, I choose this way every time.

If you upgrade the database version:

You must write the database migration code to reflect any changes in the database scheme. See here for information on migration.

An alternative to writing the database migration code is to call fallbackToDestructiveMigration in the Chamber Database Constructor. It’s probably not a good idea. If you forget to delete this call and then forget to update the database, there will be a loss of data.

// Using this fallback is almost certainly a bad idea
DatabaseBuilder(context, Database.class, DATABASE_NAME)
.build() ;

Again, there is no need to update the version of the database or perform a destructive migration if the previous scheme in the database does not live in the wild.

Solution 2:

By default, the android manifest android:allowBackup=true, which allows applications to back up their SQLite database on reinstallation.

Suppose DATABASE_VERSION was originally 3, and then you decide to reduce the database version from 3 to 1.

@Database(entities = {CallRecording.class}, version = DATABASE_VERSION)
public abstract class AppDatabase extends RoomDatabase {
public abstract recordingDAO recordDAO() ;

// Static lock Migration MIGRATION_1_2 = new Migration(1, 2) {
// @Override
// public void migrationrate(SupportSQLiteDatabase) {
// // Since we have not changed the table, there is nothing else to do here.
// }
// } ;

You can arrange it like this.

  • Delete the request data in the parameters. This deletes the old database (DATABASE_VERSION =3) from the phone.
  • Uninstall your application
  • DATABASE_VERSION down to 1
  • Rebuilding and reinstallation of your application

It is good practice to keep the DATABASE_VERSION as a constant.

Solution 3:

android: allowBackup=true in AndroidManifest.xml prevents the deletion of data even after uninstalling the application.

Add this to your manifesto:

android: allowBackup=false

and reinstall the application.

Pay attention: Be sure to reset it later if you want an automatic backup.

Another solution:

Check theeHash identity of your old json file and the new json file in the appschedule folder.

If the IDHash is different, an error occurs. Find out what you’ve changed by comparing the two json files if you don’t want to change anything.

Make sure you have exportSchedule = true.

@Database(entities = {MyEntity.class, …}, version = 2, exportSchedule = true)

Johnson’s schematic file:

formatVersion: 1, database
: {
version: 2,
identityHash: 53cc5ef34d2ebd33c8518d79d27ed012,
entities: [


private void checkIdentity(SupportSQLiteDatabase db) {
String identityHash = null ;
if (hasRoomMasterTable(db))) {
cursor = db.request(new SimpleSQLiteQuery(RoomMasterTable.READ_QUERY))) ;
// no inspection TryFinallyCanBeTryWithResources
try {
if (cursor.moveToFirst()) {
identityHash = cursor.getString(0);
} finally {
if (! mIdentityHash.equals(identityHash) &&! mLegacyHash.equals(identityHash)) {
throws a new illegal state exception (the chamber cannot check data integrity. It seems that
+ you have changed the scheme, but forgot to update the version number. You can easily correct this by increasing
+ the version number);

Solution 4:

Aniruddh Parihar’s answer gave me a clue and solved it.

Find a class where you have an extensive RoomDatabase. You will find a version as below:

@Database(entities = {YourEntity.class}, version = 1)

Just upgrade the version and the problem is solved.

Solution No 5:

It’s very simple, as the magazine shows.

It looks like you’ve changed the schema, but forgot to update the version number of the database.
You can easily fix this by increasing the version number.

Just go to the Database Version class and update the database version from 1 to the current version.

For example: Locate the database annotation in your project as shown below.

@Database(entities = {YourEntityName.class}, version = 1)

Here is the version = 1, it is the version of the database, it is enough to raise the unit
, it’s all.

Solution No 6:

1:- It seems that we need to update the version of the database (increase by 1).

2. Uninstall the application or remove data from the application.

Solution No 7:

On an Android phone:

Delete the request or delete the request data

Delete data from the request :
Go to Settings -> Applications -> Select your application -> Memory -> Delete data

Uninstalling (and reinstalling) does not work in all cases, so try to uninstall the data first!

Solution No 8:

In my case, android:allowBackup=false from true to false worked the way it used to give me nightmares, this is the strangest reason why this setting is enabled by default!

Solution No 9:

To solve the problem in Kotlin:


@database (entities = [contact::class], version = 2)


Val MIGRATION_1_2 = Object : Migration(1, 2) {override fun migrationrate(DB: SupportSQLiteDatabase) {database.execSQL(ALTER TABLE CONTACT ADD COLUMN seller_id TEXT NOT NULL DEFAULT ”)}.


private fun buildDatabase(context : Context) = Room.databaseBuilder(

More information can be found in the official documentation

Solution No 10:

This problem mainly occurs in the development process.

If you change the schema, i.e. rename/add/change the class containing the table entity, there will be conflicts between the integrity of the database output of the previous version and that of the new version.

Remove the data from the application or install a new version after uninstalling the previous one.

The old comic will not conflict with the new one.

Good luck!

Related Tags:

android studio clear app data,how room migration works,change database version in room,room change schema,android-room migration not working,migration in room database android example,migration didn't properly handle,roomdatabasebuilder,room database builder,android clear app data,exception while computing database live data.,room migration sample,room migration kotlin,android-room migration change column type,fallbacktodestructivemigration,room cannot create an sqlite connection to verify the queries,room migration add new table,room export schema,android room reset database,android room update database