简体   繁体   English

必须在会议室中从2迁移到1

[英]A migration from 2 to 1 is necessary, in Room

I have an app which makes a database by Room. 我有一个应用程序,它可以按Room来建立数据库。 Then I move the database to the server to populated. 然后,我将数据库移至要填充的服务器。 While updating or initializing the app, the populated database is downloaded by the app. 在更新或初始化应用程序时,由应用程序下载填充的数据库。 But when I want to use it by Room I get an error message: 但是当我想在房间使用它时,我收到一条错误消息:

A migration from 2 to 1 is necessary. 从2迁移到1是必要的。 Please provide a Migration in the builder or call fallbackToDestructiveMigration in the builder in which case Room will re-create all of the tables. 请在构建器中提供“迁移”,或在构建器中调用fallbackToDestructiveMigration,在这种情况下,Room将重新创建所有表。

I cleaned whole build folder then I did all again. 我清理了整个构建文件夹,然后又做了一遍。 But I get the same error again! 但是我又遇到了同样的错误!

Where I get error is: 我得到错误的地方是:

String SALE_DATABASE_NAME = "SaleDatabase.db";
SaleDatabase saleDatabase = Room.databaseBuilder(this,
        SaleDatabase.class, SALE_DATABASE_NAME)
        //.fallbackToDestructiveMigration()    
        .allowMainThreadQueries()
        .build();
saleDatabase.getPathDao().getPaths(); //Getting error

Database class: 数据库类:

@Database(entities = {OrderEntity.class, OrderDetailEntity.class
        , CardIndexDetailEntity.class, CardIndexEntity.class
        , CategoryEntity.class, CodingEntity.class
        , CustomerBasicEntity.class, CustomerBuyEntity.class
        , CustomerChequeEntity.class, CustomerCreditEntity.class
        , PathEntity.class, UnvisitedCustomerReasonEntity.class
        , ProfileCategoryEntity.class, SubCategoryDetailEntity.class
        , SubCategoryEntity.class, ReasonEntity.class}, version = 1)
public abstract class SaleDatabase extends RoomDatabase{

    public abstract PathDao getPathDao();

    @Override
    protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) {
        return null;
    }

    @Override
    protected InvalidationTracker createInvalidationTracker() {
        return null;
    }
}

My hash code in both database and SaleDatabase_Impl.java class is same. 我在数据库和SaleDatabase_Impl.java类中的哈希码是相同的。

So my questions are: 所以我的问题是:

  1. Why does it say migration 2 to 1 as a downgraded job? 为什么说迁移2迁移到1是降级的工作?
  2. How can I ignore version until application built completely 在应用程序完全构建之前,如何忽略版本
  3. Is there a way to clean and reset room if I update my version to 2? 如果我将版本更新为2,是否可以打扫并重置房间?

I solved this way: 我这样解决了:

  1. Clear app data 清除应用数据
  2. In the manifest set android:allowBackup="false" 在清单中设置android:allowBackup="false"

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

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