简体   繁体   English

在开发过程中保留Room数据库版本号

[英]Keep Room database version number during development

Is it possible to keep the database version number during development? 在开发过程中是否可以保留数据库版本号? I'm new to Android Dev and Room so I'm building my app piece by piece testing the functionality as I go. 我是Android Dev和Room的新手,所以我会逐段测试功能,以构建自己的应用程序。 As such every time I create a new entity I have to update my database version number. 因此,每次创建新实体时,都必须更新数据库版本号。

During development is it possible to set a flag to ignore changes? 在开发过程中是否可以设置标记以忽略更改?

So far I've just used .fallbackToDestructiveMigration() when upping the version number, but then I obviously need to make sure I remove this. 到目前为止,在增加版本号时,我只使用了.fallbackToDestructiveMigration() ,但是显然我需要确保将其删除。 Is there a better way? 有没有更好的办法?

The simple answer to this question is no, there is not. 这个问题的简单答案是不,没有。 Saying this there is a way to get around this issue. 说这是解决此问题的一种方法。 When you do a database change you only need to change the version number which will trigger a migration script - in your case simply destroying the database and creating the new one. 更改数据库时,只需更改版本号即可触发迁移脚本-在您的情况下,只需破坏数据库并创建新的脚本即可。 When you want to release your product simply reset the version number to the one you require. 当您要发布产品时,只需将版本号重置为所需的版本号即可。 That way you can continually test but still have reasonable version numbers for your live application. 这样,您可以不断测试,但仍为您的实时应用程序提供合理的版本号。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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