Siamak Ferdos
Siamak Ferdos

Reputation: 3299

A migration from 2 to 1 is necessary, in Room

I have an app which makes a database by 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. Please provide a Migration in the builder or call fallbackToDestructiveMigration in the builder in which case Room will re-create all of the tables.

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.

So my questions are:

  1. Why does it say migration 2 to 1 as a downgraded job?
  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?

Upvotes: 4

Views: 898

Answers (1)

Nicola De Fiorenze
Nicola De Fiorenze

Reputation: 2128

I solved this way:

  1. Clear app data
  2. In the manifest set android:allowBackup="false"

Upvotes: 3

Related Questions