SQLite修改列
我需要修改SQLite数据库中的列,但是由于数据库已经在生产中,因此我必须以编程方式进行修改。从我的研究中,我发现要执行此操作,必须执行以下操作。
I need to modify a column in a SQLite database but I have to do it programatically due to the database already being in production. From my research I have found that in order to do this I must do the following.
- 使用新模式创建新表
- 将数据从旧表复制到新表
- 删除旧表
- 将新表重命名为旧表名称
- Create a new table with new schema
- Copy data from old table to new table
- Drop old table
- Rename new table to old tables name
对于一些相对容易的事情来说,这似乎是荒谬的工作。有没有更简单的方法?我需要做的就是更改现有列的约束并为其提供默认值。
That seems like a ridiculous amount of work for something that should be relatively easy. Is there not an easier way? All I need to do is change a constraint on a existing column and give it a default value.
那是更好的方法之一SQLite的已知缺点( ALTER TABLE
不支持 MODIFY COLUMN
),但它在 SQLite未实现的SQL功能列表。
That's one of the better-known drawbacks of SQLite (no MODIFY COLUMN
support on ALTER TABLE
), but it's on the list of SQL features that SQLite does not implement.
编辑:删除了提及此内容的位,因为该页面已更新,表明不再适用了,因此将来的版本中可能会支持它。
edit: Removed bit that mentioned it may being supported in a future release as the page was updated to indicate that is no longer the case