Room - Миграция не прошла должным образом - Android - PullRequest
0 голосов
/ 23 июня 2019

Я использую с 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 голосов
/ 23 июня 2019

В этом методе необходимо добавить текст миграции с новыми столбцами

@Override
        public void migrate(SupportSQLiteDatabase db) {

        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...