[英]Migrating room database in android
I just updated my database in android and can't get an app to migrate. 我刚刚在android中更新了数据库,无法迁移应用。
The change I made is that I added ( autoGenerate = true
) to my @PrimaryKey
我所做的更改是我向
@PrimaryKey
添加了( autoGenerate = true
)
@PrimaryKey(autoGenerate = true)
private int id;
I tried a whole lot of things, but I cannot get the migration to work. 我尝试了很多事情,但无法进行迁移。
The problem arises in my AppDatabase class where i inserted following code: 在我插入以下代码的AppDatabase类中出现了问题:
public static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE inventory");
}
};
The ALTER TABLE
inventory isn't the right command but I cannot figure out what is ALTER TABLE
库存不是正确的命令,但是我无法弄清楚是什么
The SQL statement is incorrect ALTER TABLE inventory
. SQL语句的
ALTER TABLE inventory
不正确。 You did not specify what is going to be changed on the table. 您没有在表上指定要更改的内容。
For example: ALTER TABLE inventory ADD name TEXT
that means there is a new column name
in type TEXT
to be added in the table inventory
. 例如:
ALTER TABLE inventory ADD name TEXT
意味着在TEXT
类型中有一个新的列name
要添加到表inventory
。
While your case is a constraint change, and there is no way to alter constraint. 虽然您的情况是一个约束更改,但无法更改约束。 But you can drop the constraint and add it again.
但是您可以删除约束并再次添加它。
Please read the answer here: How to Alter Constraint 请在此处阅读答案: 如何更改约束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.