Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我将数据库从版本 1 升级到版本 2 并插入新数据时,存储在数据库版本 1 中的所有旧数据都被删除,我只能在数据库中看到新插入的数据。
知道如何在使用 Room Library 升级数据库时保留数据吗?
我从同一个链接找到了解决方案。当没有提供迁移类时,Room Library 会删除整个数据库,其中包含 onUpgrade() 上的数据并再次创建数据库。
如果要在 onUpgrade() 上持久化数据,则必须提供Migration 类