Segue o erro
03-21 15:46:53.779 18409-18409/com.paris.listaalunos E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.paris.listaalunos, PID: 18409
java.lang.RuntimeException: Unable to resume activity {com.paris.listaalunos/com.paris.listaalunos.ui.activity.ListStudentActivity}: 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.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
@Database(entities = {Student.class}, version = 2, exportSchema = false)
public abstract class ListStudentDataBase extends RoomDatabase {
public static final String AGENDA_DB = "agenda.db";
private static ListStudentDataBase instance;
public abstract StudentDao getRoomStudentDao();
public static ListStudentDataBase getInstance(Context context){
if(instance == null){
instance = Room.databaseBuilder(context, ListStudentDataBase.class, AGENDA_DB)
.allowMainThreadQueries().addMigrations(new Migration(1, 2) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE Student ADD COLUMN lastName TEXT");
}
}, new Migration(2 , 3) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS `Student_new` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `phone` TEXT, `email` TEXT)");
database.execSQL("INSERT INTO Student_new (id, name, phone, email) SELECT id, name, phone, email FROM Student");
database.execSQL("DROP TABLE Student");
database.execSQL("ALTER TABLE Student_new RENAME TO Student");
}
})
.build();
}
return instance;
}
}