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

标签 database flutter sqlite dart 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
       )''');

关于database - 如何在 sqflite 的数据库中创建多个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54316131/

相关文章:

c - C中的节点和链表语法

php - 更新 SQL 列

flutter - 未为对象定义 Getter

flutter - `on`子句未捕获引发的异常(类型似乎错误)

c++ - SQLite INSERT 命令返回错误 "column number is not unique"

mysql - 如何在 firebird 中插入另一个表中的行?

ruby-on-rails - 仍然允许搜索的 Rails 加密列

laravel-5 - 从 laravel API 检索数据到 flutter 应用程序

ruby-on-rails - 查找带有 ID 的对象名称

android - SQLite - 保存更改的最快方法