首页 > 解决方案 > sqflite 中的多个表

问题描述

我对 Flutter 很陌生,我只想设置一个包含多个表的 SQLite 数据库。我的研究如下。

提前致谢。

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

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
       )''');

调用 sqlite3_step 的未知错误(10:磁盘 I/O 错误)rs

标签: dartfluttersqflite

解决方案


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

void _createDb(Database db, int newVersion) async {
    await db.execute(
        'CREATE TABLE $noteTable($colId INTEGER PRIMARY KEY AUTOINCREMENT, $colTitle TEXT, '
        '$colDescription TEXT, $colPriority INTEGER, $colDate TEXT)');

 await db.execute(
        'CREATE TABLE $noteTable($colId INTEGER PRIMARY KEY AUTOINCREMENT, $colTitle TEXT, '
        '$colDescription TEXT, $colPriority INTEGER, $colDate TEXT)');
  }

推荐阅读