во время миграции базы данных в комнате, она показывает ошибку - PullRequest
0 голосов
/ 16 февраля 2019

Я переношу базу данных из версии 2 в версию 3. Но она показывает ошибку типа

. Причина: java.lang.IllegalStateException: миграция неправильно обработала user_info_job (com.nsas.bharatnext.DataBase.JobUserInfoTable).Ожидается:

TableInfo {name = 'user_info_job', столбцы = {sl_no = Column {name = 'sl_no', type = 'TEXT', affinity = '2', notNull = false, primaryKeyPosition = 0},user_PIN_code = Column {name = 'user_PIN_code', type = 'TEXT', affinity = '2', notNull = false, primaryKeyPosition = 0}, user_email = Column {name = 'user_email', type = 'TEXT', affinity = '2 ', notNull = false, primaryKeyPosition = 0}, user_door_no = столбец {name =' user_door_no ', тип =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_name = Column {name ='user_name ', type =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_diploma = столбец {name =' user_diploma ', type =' TEXT ', affinity =' 2 ', notNull = false,primaryKeyPosition = 0}, id_val = столбец {name = 'id_val', type = 'INTEGER', affinity = '3', notNull = true, primaryKeyPosition = 1}, user_specialisation = Column {name = 'user_specialisation', type = 'TEXT', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_city = Столбец {name =' user_city ', тип =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_gender = Столбец {name = 'user_gender', тип = 'TEXT', affinity = '2', notNull = false, primaryKeyPosition = 0}, user_date_of_birth = Column {name = 'user_date_of_birth', type = 'TEXT', affinity = '2 ', notNull = false, primaryKeyPosition = 0}, user_marital_status = Column {name =' user_marital_status ', type =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_ward = Column {name ='user_ward ', type =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_state = столбец {name =' user_state ', type =' TEXT ', affinity =' 2 ', notNull = false,primaryKeyPosition = 0}, user_educational_qualification = Column {name = 'user_educational_qualification', type = 'TEXT', affinity = '2', notNull = false, primaryKeyPosition = 0}, user_mobile_num = Column {name = 'user_mobile_num', type = 'TEXT', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_course = Column {name =' user_course ', type =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_12th =Столбец {name = 'user_12th', type = 'TEXT', affinity = '2', notNull = false, primaryKeyPosition = 0}, user_locality = столбец {name = 'user_locality', тип = 'TEXT', affinity = '2', notNull = false, primaryKeyPosition = 0}, user_sub_city = Column {name = 'user_sub_city', тип = 'TEXT', affinity = '2 ', notNull = false, primaryKeyPosition = 0}, user_street_name = Column {name =' user_street_name ', type =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_caste = Column {name ='user_caste ', type =' TEXT ', affinity =' 2 ', notNull = false, primaryKeyPosition = 0}, user_10th = столбец {name =' user_10th ', type =' TEXT ', affinity =' 2 ', notNull = false,primaryKeyPosition = 0}, job_sl_no = столбец {name = 'job_sl_no', type = 'TEXT', affinity = '2', notNull = false, primaryKeyPosition = 0}}, foreignKeys = [], indices = []}

@ База данных (entity = {UserInfoTable.class, JobUserInfoTable.class, PolicyUserInfoTable.class, WorkForYouTable.class, UserDetailsTable.class}, версия = 3, exportSchema = false) @TypeConverters ({Converter.class}) открытый абстрактный классMyAppDataBase расширяет RoomDatabase {

public abstract MyDao myDao();

public abstract UserDAO userDAO();

public static MyAppDataBase mInstance;

public static MyAppDataBase getInstance(Context context){
    if(mInstance!=null){
        mInstance= Room.databaseBuilder(context,MyAppDataBase.class,"userdb")
                 .addMigrations(MIGRATION_2_3)
                 .build();
    }
    return mInstance;
}

public static final Migration MIGRATION_1_2 = new Migration(1, 2) {
    @Override
    public void migrate(@NonNull SupportSQLiteDatabase database) {
        database.execSQL(
                "CREATE TABLE work_for_you_info (state TEXT, city TEXT, consistency TEXT, PRIMARY KEY(slno))");
    }

};
public static final Migration MIGRATION_2_3 = new Migration(2, 3) {
    @Override
    public void migrate(@NonNull SupportSQLiteDatabase database) {
        database.execSQL("DROP TABLE user_info_job");
        database.execSQL("DROP TABLE user_info_policy");
        database.execSQL("DROP TABLE work_for_you_info");
        database.execSQL(
                "CREATE TABLE user_details (user_sl_no TEXT,name TEXT, email TEXT, mobile_num TEXT," +
                        "date_of_birth TEXT,religion TEXT, caste TEXT, subCaste TEXT," +
                        "occupation TEXT,state TEXT, district TEXT, constituency TEXT," +
                        "village TEXT,ward TEXT, gender TEXT, marital_status TEXT," +
                        "door_no TEXT,street_name TEXT, locality TEXT, PIN_code TEXT," +
                        "educational_qualification TEXT,course TEXT, specialisation TEXT, disabled TEXT," +
                        "userRelation TEXT)");
    }

};

}

...