会议室-迁移不正确-Android

时间:2019-06-23 13:19:53

标签: android android-room android-architecture-components

我正在使用Room中的产品,我正在使用addMigrations中的1 to 2中的产品,但是请说:

 Expected:
TableInfo{name='tblCourseContentList', columns={downloadPackageSize=Column{name='downloadPackageSize', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, id_0=Column{name='id_0', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}, downloadPackageUrl=Column{name='downloadPackageUrl', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, status=Column{name='status', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, id_courseContentList=Column{name='id_courseContentList', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1}, sections=Column{name='sections', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
 Found:
TableInfo{name='tblCourseContentList', columns={}, foreignKeys=[], indices=null}

这是我的AppDataBase.java

@Database(entities = {ClassModel.class,
        CourseContentListModel.class,
        _0.class,
        Section.class,
        Content.class,
        DownloadBatchIdsSubCourse.class,
        DownloadBatchIdsMainCourse.class
}, version = 2, exportSchema = false)
@TypeConverters({
        EnrollConverter.class,
        TeacherConverter.class,
        DetailConverter.class,
        Detail_Converter.class,
        Detail__Converter.class,
        //region CourseContentList
        SectionConverter.class,
        ContentConverter.class,
        ConverterListsCourseContentList.class
        //endregion
})
public abstract class AppDatabase extends RoomDatabase {
    public static final String DATABASE_NAME = "MyDatabase.db";
    private static volatile AppDatabase instance;
    private static final Object LOCK = new Object();

    public abstract WorkTableDao workTableDao();

    public abstract CourseContentListDao courseContentListDao();

    public abstract CourseContentSubListDao courseContentSubListDao();

    public static AppDatabase getInstance() {
        if (instance != null) {
            return instance;
        } else {
            return null;
        }
    }


    private static final Migration MIGRATION_LATEST = new Migration(1, 2) {
        @Override
        public void migrate(SupportSQLiteDatabase db) {

        }
    };

    public static AppDatabase getInstance(Context context) {
        if (instance == null) {
            synchronized (LOCK) {
                if (instance == null) {
                    instance = Room.databaseBuilder(context.getApplicationContext(),
                            AppDatabase.class, DATABASE_NAME)
                            .addMigrations(MIGRATION_LATEST)
                            .build();
                }
            }
        }

        return instance;
    }
}

1 个答案:

答案 0 :(得分:0)

您必须在此方法中添加带有新列的迁移文本

@Override
        public void migrate(SupportSQLiteDatabase db) {

        }