我为我的SQLite Db进行了DbFlow迁移。我添加了两列,构建成功 问题是我无法在User表中的任何位置看到这些列,并且我无法插入或读取它们中的数据。可能是什么问题?
我的迁移代码。
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");
}
}
}
答案 0 :(得分:0)
将数据库版本升级为可更改版本。 在模型中使用相同的名称,否则使用列名注释
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");
}
}
/// Model例如
@Column(name = "time_sent")
long timeSent;