房间迁移问题

时间:2020-06-30 15:33:34

标签: android android-room

我正在将我的应用程序从SQqlite迁移到Room数据库。

我有以下用于房间迁移的代码。

 static final Migration MIGRATION_18_19 = new Migration(18, 19) {
    @Override
    public void migrate(
            SupportSQLiteDatabase database) {
        database.execSQL("ALTER TABLE " + “user_records" + " ADD COLUMN " + "extra_values" + " TEXT");
        database.execSQL("ALTER TABLE " + “user_records" + " ADD COLUMN " + "form_url" + " TEXT");
    }
};

static final Migration MIGRATION_19_20 = new Migration(19, 20) {
    @Override
    public void migrate(SupportSQLiteDatabase database) {
        // Create the new table
        database.execSQL(
                "CREATE TABLE " + UserEntity.TABLE_NAME + "_new" + " (" +
                        UserEntity.COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                        UserEntity.COLUMN_REMOTE_ID + " TEXT,"+
                        UserEntity.COLUMN_NAME + " TEXT,"+
                        UserEntity.COLUMN_STATUS + " INTEGER,"+
                        UserEntity.COLUMN_TYPE + " TEXT,"+
                        UserEntity.COLUMN_STAGE + " TEXT,"+
                        UserEntity.COLUMN_AMOUNT + " TEXT,"+
                        UserEntity.COLUMN_CLOSE_DATE + " TEXT,"+
                        UserEntity.COLUMN_TARGET + " TEXT,"+
                        UserEntity.COLUMN_DISPLAY + " TEXT,"+
                        UserEntity.COLUMN_SELECTED_DISPLAY + " TEXT,"+
                        UserEntity.COLUMN_EXTRA_VALUES + " TEXT,"+
                        UserEntity.COLUMN_FORM_URL + " TEXT);"
        );

        // Copy the data
        database.execSQL(
                "INSERT INTO user_records_new (_id,remote_id,name,status,type,stage,amount,close_date,target,display,selected_display, extra_values,form_url) SELECT _id,remote_id,name,status,type,stage,amount,close_date,target,display,selected_display, extra_values,form_url FROM user_records");
 // Remove the old table
        database.execSQL("DROP TABLE user_records");
 // Change the table name to the correct one
        database.execSQL("ALTER TABLE user_records_new RENAME TO user_records");
    }
};

即使我在迁移18_19中添加了列,为什么也无法获得例外

no such column: form_url (Sqlite code 1): , while compiling: INSERT INTO user_records_new (_id,remote_id,name,status,type,stage,amount,close_date,target,display,selected_display, extra_values,form_url) SELECT _id,remote_id,name,status,type,stage,amount,close_date,target,display,selected_display, extra_values,form_url FROM user_records, (OS error - 2:No such file or directory)

应用中的数据库版本为20。

0 个答案:

没有答案