database - 如何在 sqflite 的数据库中创建多个表?

我正在使用使用 SQLite 数据库的 flutter 构建和应用程序。我使用这段代码创建了第一个表:

 void _createDb(Database db, int newVersion) async {
    await db.execute('''CREATE TABLE cards (id_card INTEGER PRIMARY KEY, 
         color TEXT, type TEXT, rarity TEXT, name TEXT UNIQUE, goldCost INTEGER,
         manaCost INTEGER, armor INTEGER, attack INTEGER, health INTEGER, description TEXT)''');
}

表已创建,我可以毫无问题地访问它。

不幸的是,我不能包含超过 1 个我刚刚创建的表。我尝试在同一方法中添加另一个 SQL CREATE TABLE 子句,并在下一行使用不同的 SQL 子句重复方法 db.execute

我正在模仿本教程中的代码:https://www.youtube.com/watch?v=xke5_yGL0uk

如何在同一个数据库中添加另一个表?

最佳答案

例如,您可以组合多个 db.execute 调用

await db.execute('''
      create table $reminderTable (
        $columnReminderId integer primary key autoincrement,
        $columnReminderCarId integer not null,
        $columnReminderName text not null,
        $columnReminderNotifyMileage integer not null,
        $columnReminderEndMileage integer not null
       )''');
await db.execute('''
       create table $carTable (
        $columnCarId integer primary key autoincrement,
        $columnCarTitle text not null
       )''');

https://stackoverflow.com/questions/54316131/

相关文章:

dart - 如何在 Google Maps Flutter 插件上添加折线?

dart - Navigator routes 清除flutter的堆栈

flutter - Flutter 是否也在 iOS 上使用 Skia 进行渲染?

dart - 如何在 Flutter 小部件测试中等待 future 完成?

flutter - 在 Flutter 中的 TabBar 顶部添加指示器

dart - Flutter:获取 HTML 页面的某些元素

dart - Flutter:启动时共享首选项为空

dart - flutter 构造函数错误

dart - 如何在 flutter 中拆分 Dart 类?

dart - 将 "uint8list"的字符串转换为 Unit8List