如何访问SQlite上的id



我不知道如何解决这个错误

class ToDo {
final int id;
final String category;
final String name;
final int year;
final int month;
final int date;
final int intdone;
ToDo({required this.id,
required this.category,
required this.name,
required this. year,
required this. month,
required this. date,
required this. intdone,
});
}
}
final String TableName2 = 'ToDoList';
Future<Database> get database2 async {
if (_db2 != null) return _db2;
_db2 = openDatabase(
join(await getDatabasesPath(), 'ToDoList.db'),
onCreate: (db, version) {
return db.execute(
'CREATE TABLE ToDoList(id INTEGER, category TEXT, name TEXT, year INTEGER, month INTEGER, date INTEGER, intdone INTEGER)',
);
},
version: 1,
);
return _db2;
}
Future<void> insertToDo(ToDo todo) async {
final db = await database2;
await db.insert(
TableName2,
todo.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
}
floatingActionButton: FloatingActionButton(
child: Icon(Icons.check),
onPressed: () {
sd.insertToDo(ToDo(id: 0, category: 'd', name: 'd', year: 2022, month: 10, date: 18, intdone: 0));
},
),

该代码返回错误

E/SQLiteLog(30805(:(1(表ToDoList中没有名为"done"的列;插入或替换到ToDoList(id,category,name,year,month,date,done(值(;E/flutter(30805(:[错误:flutter/runtime/dart_vm_initializer.cc(41(]未处理的异常:DatabaseException(表ToDoList没有命名为done的列(代码1 SQLITE_ERROR(:,编译时:INSERT或REPLACE INTO ToDoList(id,category,name,year,month,date,done

我正在做todolist,当我按下floatingActionButton时,我做了添加。

当我执行insertToDo函数时,它不起作用。

错误消息告诉我没有在表ToDoList中创建列id,但我找不到原因。

无论出于何种原因,intdone都会更改为done,即不是

INSERT OR REPLACE INTO ToDoList (id, category, name, year, month, date, intdone /*<<<<<<<<<<*/) VALUES (....

正在使用以下内容:-

INSERT OR REPLACE INTO ToDoList (id, category, name, year, month, date, done /*??????????*/) VALUES (....

当根据todo.toMap(),对传递的Todo应用toMap()函数时,它似乎发生了变化。

最新更新