Room cannot verify the data integrity

前端 未结 20 2332
一向
一向 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:12

    If increasing schema version didn't work with you, provide migration of your database. To do it you need to declare migration in database builder:

    Room.databaseBuilder(context, RepoDatabase.class, DB_NAME)
      .addMigrations(FROM_1_TO_2)
    .build();
    
    static final Migration FROM_1_TO_2 = new Migration(1, 2) {
    @Override
    public void migrate(final SupportSQLiteDatabase database) {
        database.execSQL("ALTER TABLE Repo 
                         ADD COLUMN createdAt TEXT");
        }
    };
    

提交回复
热议问题