Android 使用迁移更改列的房间类型
Android Room change type of column with Migration
我没有找到我正在搜索的任何答案,所以我发送了这个问题。
我正在为 Android 使用 Room。
我有一个包含 Int 列的实体,我需要将其更改为 Double,但我不知道该怎么做。
有人知道怎么做吗?
我的问题可能很愚蠢,但我在 Whosebug/any google 搜索中没有找到任何答案。
您需要使用新架构创建新的 table。
将数据从旧的 table 复制到新的。
删除旧 table。
将新 table 重命名为旧 table.
的名称
这里有一篇很好的文章:
https://medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929
如 here 上的 sqlite 文档中所述,sqlite 不支持更新列类型。
SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE
command in SQLite allows the user to rename a table or to add a new
column to an existing table. It is not possible to rename a colum,
remove a column, or add or remove constraints from a table.
正如 Sebastian M 所指出的,您需要创建新的 table 添加新列,将数据从旧的 table 复制到新的.放弃旧 table。将新 table 重命名为旧 table.
的名称
我没有找到我正在搜索的任何答案,所以我发送了这个问题。
我正在为 Android 使用 Room。
我有一个包含 Int 列的实体,我需要将其更改为 Double,但我不知道该怎么做。
有人知道怎么做吗?
我的问题可能很愚蠢,但我在 Whosebug/any google 搜索中没有找到任何答案。
您需要使用新架构创建新的 table。 将数据从旧的 table 复制到新的。 删除旧 table。 将新 table 重命名为旧 table.
的名称这里有一篇很好的文章: https://medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929
如 here 上的 sqlite 文档中所述,sqlite 不支持更新列类型。
SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a colum, remove a column, or add or remove constraints from a table.
正如 Sebastian M 所指出的,您需要创建新的 table 添加新列,将数据从旧的 table 复制到新的.放弃旧 table。将新 table 重命名为旧 table.
的名称