Room database upgrade

  • First class inheritance among RoomBase definition Migration
    •   
          static Migration migration = new Migration(1,2) {
              @Override
              public void migrate(@NonNull SupportSQLiteDatabase database) {
                  database.execSQL("alter table student_table ADD  COLUMN begin_time INTEGER NOT NULL DEFAULT 0");
              }
          };

       

  • RooDataBase (). AddMigrations (migration) .build
    •   
      Room.databaseBuilder(mContext.getApplicationContext(),WorkRoomDataBase.class,"work_database")
                                  .addMigrations(ALL_MIGRATIONS)
              ....

       

  • Note that the definition INTEGER field when the need to add NOT NULL DEFAULT 0, otherwise the report was wrong (IlegalStateException)

Guess you like

Origin www.cnblogs.com/endian11/p/11950657.html