我是新手,我学习sqflite。并且我遇到一个错误DatabaseException(表电影没有名为Title(代码1)的列,而正在编译:INSERT INTO movie(Id,Title,Description,Image,Genre,Video ,Year,Casts,type)VALUES(NULL,?,?,?,?,?,?,NULL,?,?))sql。我不知道我在哪里错。这是我的TodoHelper类。
class TodoHelper {
final String tableName = "movie";
final String Id = "Id";
final String Title = "Title";
final String Image = 'Image';
final String Genre = 'Genre';
final String Video = 'Video';
final String Description = 'Description';
final String Year = 'Year';
final String Casts = 'Casts';
final String type = 'type';
Database db;
TodoHelper() {
initDatabase();
}
Future<void> initDatabase() async {
db = await openDatabase(join(await getDatabasesPath(), "databse.db"),
onCreate: (db, version) {
return db.execute(
"CREATE TABLE $tableName($Id INTEGER PRIMARY KEY AUTOINCREMENT, $Title TEXT, "
"$Image TEXT, "
"$Genre TEXT, "
"$Video TEXT, "
"$Description TEXT, "
"$Year TEXT, "
"$Casts TEXT, "
"$type TEXT) ");
}, version: 1);
print('db created');
}
Future<void> insertMovie(MovieEntity movieEntity) async {
try {
db.insert(tableName, movieEntity.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace);
} catch (_) {
print(_);
}
}
Future<List<MovieEntity>> getAllMovies() async {
final List<Map<String, dynamic>> tasks = await db.query(tableName);
return List.generate(tasks.length, (i) {
return MovieEntity(
Title: tasks[i][Title], Id: tasks[i][Id]);
});
}
}