我正在尝试从 json 对象插入数据,以下代码是关于我使用的表的
我这样定义了数据库助手类:
class DatabaseHelper {
static DatabaseHelper _databaseHelper; // Singleton DatabaseHelper
static Database _database; // Singleton Database
String category_Table = 'category_Table';
String category_id = 'category_id';
String device_type_id = 'device_type_id';
String room_id = 'room_id ';
...
await db.execute(
'CREATE TABLE $category_Table($category_id INTEGER PRIMARY KEY UNIQUE , $device_type_id INTEGER, '
'$room_id INTEGER)');
print('category created!');
这是插入功能
Database db = await this.database;
var result = await db.insert(category_Table, category.toMap());
print('category inserted');
return result;
}
这是错误
Exception has occurred.
SqfliteDatabaseException (DatabaseException(table category_Table has no column named category_id (code 1): , while compiling: INSERT INTO category_Table (category_id, device_type_id, room_id) VALUES (?, ?, ?)) sql 'INSERT INTO category_Table (category_id, device_type_id, room_id) VALUES (?, ?, ?)' args [1, 1, 1]})
感谢您的帮助:)