Answer the question
In order to leave comments, you need to log in
Why is there an error that the table does not exist?
When trying to get data from the database from the lesson table , an error appears that there is no such table.
The database is, the table too.
Future<List<Lesson>> getLessons() async {
final db = await database;
var res = await db.query("lessons");
List<Lesson> list = res.isNotEmpty ? res.map((c) => Lesson.fromMap(c)).toList() : [];
print(list);
return list;
}
initDB() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
print(documentsDirectory.path);
String path = join(documentsDirectory.path, "TestDB.db");
await deleteDatabase(path);
return await openDatabase(path, version: 1, onOpen: (Database db) {},
onCreate: (Database db, int version) async {
await db.execute("CREATE TABLE homeworks("
"id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,"
"lesson INTEGER,"
"date INTEGER,"
"homework TEXT,"
"isDone INTEGER"
");"
"CREATE TABLE lessons ("
"id INTEGER PRIMARY KEY,"
"lesson TEXT)");
});
}
Answer the question
In order to leave comments, you need to log in
It turns out db.execute() can only execute one command.
For each table, you need to call db.execute () again
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question