Flutter-如何在Sqflite中更新表结构? [英] Flutter - How to update the table structure in Sqflite?

查看:447
本文介绍了Flutter-如何在Sqflite中更新表结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在生产中,我想在用户更新应用程序时管理用户数据而不会丢失其数据,我该如何使用 sqflite 来实现这一点。明确地说,我想添加一列,然后删除另一列。

My app is in production and I want to manage user data when user updates the app without loss of their data, how can I achieve this with sqflite. Explicitly I want to add a column and delete another.

推荐答案

您可能可以使用原始SQL添加列,但sqlite(因此sqflite)不支持删除列。为此,您需要执行以下操作:

You can probably add a column using raw sql, but sqlite (and thus sqflite) doesn't support dropping a column. For that you would need to do the following:


  • 增加数据库版本号

  • onUpgrade 将旧数据库列复制到临时表中

  • 删除原始表

  • 创建一个使用原始表名但具有正确模式的新表

  • 从临时表中复制数据

  • 删除临时表

  • increase the database version number
  • in onUpgrade copy the old database columns to a temporary table
  • delete the original table
  • create a new table using the original table name but with the right schema
  • copy the data from the temp table
  • delete the temp table

对不起,这不是一个完整的答案,但这是我在您遇到的情况下要走的方向。

Sorry, this isn't a full answer, but it is the direction I would go if I were in your situation.

这篇关于Flutter-如何在Sqflite中更新表结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆