我是SQLite和ActiveAndroid的新手。
我正在努力推出应用更新并需要迁移我的数据库。某些表已添加或删除了列等。在ActiveAndroid中,通过编写迁移脚本来执行模式迁移。在处理基本数据类型时,我很容易理解如何执行此操作,但我很困惑如何添加映射到其他对象/类的列。
例如,下面是现有的模型:
@Table(name = "GatewayDevices", id = BaseColumns._ID)
public class GatewayDevice extends Model {
private static final String TAG = GatewayDevice.class.getSimpleName();
@Column(name = "identifier", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE, notNull = true)
private String identifier;
@Column(name = "deviceType", notNull = true)
private String deviceType;
@Column(name = "name")
private String name;
public GatewayDevice() {
super();
}
...
}
我正在更新它:
@Table(name = "GatewayDevices", id = BaseColumns._ID)
public class GatewayDevice extends Model {
private static final String TAG = GatewayDevice.class.getSimpleName();
@Column(name = "identifier", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE, notNull = true)
private String identifier;
@Column(name = "deviceType", notNull = true)
private String deviceType;
@Column(name = "name")
private String name;
@Column(name = "controller", onUpdate = Column.ForeignKeyAction.CASCADE, onDelete = Column.ForeignKeyAction.CASCADE)
private Controller controller;
public GatewayDevice() {
super();
}
...
}
如何使用基本ALTER TABLE GatewayDevice ADD COLUMN controller <type>
结构添加此列?
答案 0 :(得分:1)
您可以为Controller类编写自己的序列化程序,并进行迁移
ALTER TABLE GatewayDevice ADD COLUMN控制器TEXT
(字符串类型)