我正在使用使用 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/