我正在将Room db从版本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',类型='TEXT',亲和力='2',notNull = false,primaryKeyPosition = 0},user_email = Column {name ='user_email',类型='TEXT',亲和力='2',notNull = false,primaryKeyPosition = 0},user_door_no = Column {name ='user_door_no',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_name = Column {name ='user_name',type = 'TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_diploma = Column {name ='user_diploma',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0}, id_val = Column {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 = Column {name ='user_city',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_gender = Column {name =' ü ser_gender',type ='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 = Column {name ='user_state',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_educational_qualification =列{name ='user_educational_qualification',类型='TEXT',相似性='2',notNull = false,primaryKeyPosition = 0},user_mobile_num =列{name ='user_mobile_num',类型='TEXT',相似性='2' ,notNull = false,primaryKeyPosition = 0},user_course = Column {name ='user_course',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_12th = Column {name ='user_12th' ,type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_locality = Column {nam e ='user_locality',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_sub_city = Column {name ='user_sub_city',type ='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',类型='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0},user_10th = Column {name ='user_10th',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0} ,job_sl_no = Column {name ='job_sl_no',type ='TEXT',affinity ='2',notNull = false,primaryKeyPosition = 0}},外键= [],索引= []}
@Database(实体= {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)");
}
};
}