table has no column flutter

Viewed 586

I am new in flutter.I learn sqflite.And i have an error DatabaseException(table movie has no column named Title (code 1), while compiling: INSERT INTO movie (Id, Title, Description, Image, Genre, Video, Year, Casts, type) VALUES (NULL, ?, ?, ?, ?, ?, NULL, ?, ?)) sql. I dont know where i have mistake. It is my TodoHelper class.

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]);
            });
          }
        }
1 Answers
await db.execute('''
  CREATE TABLE $_tblLogTable(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    requestid INTEGER ,
    userid TEXT NOT NULL,
    deviceno1 INTEGER NOT NULL, 
    deviceid1 TEXT NOT NULL,
    use_status1 INTEGER , 
  )''');

You forgot to put comma , it should be as "$Image TEXT", "$Genre TEXT",...

Related