简体   繁体   中英

room migration failure fallback android

For android's room migrations, are there any methods or techniques that allow a fallback for if for some odd reason (not missing schema - I already know about the fallbackToDestructiveMigration method) a migration fails? ie to nuke and recreate the entire db?

Just wrap the whole thing in a try catch block.

Source: used it for a migration with 20m+ users. No crashes directly related to the migration

There is a fallbackToDestructiveMigration() method available on the room builder class that is used to generate the database. ( Room.databaseBuilder )

The method explains itself:) It removes the data in Room when the migration fails

Room.databaseBuilder(getApplicationContext(), MyDatabase.class, "database-name")
    .fallbackToDestructiveMigration()
    .build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM