0

我为我的 SQLite Db 进行了 DbFlow 迁移。我添加了两列并且构建成功问题是我在用户表中的任何地方都看不到这些列,我无法从它们插入或读取数据。可能是什么问题呢 ?

我的迁移代码。

package com.omnitech.elunda.mobile.database;

import com.raizlabs.android.dbflow.annotation.Database;
import com.raizlabs.android.dbflow.annotation.Migration;
import com.raizlabs.android.dbflow.sql.SQLiteType;
import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration;

/**
 * Created by magicwand on 9/28/2017.
 * Database class to manage datastore
 */

@Database(name=ELundaDatabase.name , version=ELundaDatabase.VERSION)
public class ELundaDatabase {

    public static final String name ="ElundaDatabase";
    public static final int VERSION =1;

    @Migration(version = ELundaDatabase.VERSION +1, database=ELundaDatabase.class)
    public static class Migration1 extends AlterTableMigration<User> {


        public Migration1(Class<User> table) {
            super(table);
        }

        @Override
        public void onPreMigrate() {
            super.onPreMigrate();
            addColumn(SQLiteType.TEXT, "phoneNumber");
            addColumn(SQLiteType.TEXT, "password");
        }
    }



}
4

1 回答 1

1

将数据库版本升级到与可更改版本相同的版本。在模型中使用相同的名称也使用列名注释

public static final String name ="ElundaDatabase";
public static final int VERSION = 2;


@Migration(version = 2, database=ELundaDatabase.class)
public static class Migration1 extends AlterTableMigration<User> {


    public Migration1(Class<User> table) {
        super(table);
    }

    @Override
    public void onPreMigrate() {
        super.onPreMigrate();
        addColumn(SQLiteType.TEXT, "phoneNumber");
        addColumn(SQLiteType.TEXT, "password");
    }
}

/// 模型例如

@Column(name = "time_sent")
long timeSent;
于 2017-10-05T15:32:46.253 回答