Flutter DataBaseException(表category_Table没有名为category_id的列)

Elh*_*arz 4 dart flutter sqflite

我正在尝试从 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 ';
...

Run Code Online (Sandbox Code Playgroud)
await db.execute(
      'CREATE TABLE $category_Table($category_id INTEGER PRIMARY KEY UNIQUE  , $device_type_id INTEGER, '
                '$room_id INTEGER)');
        print('category created!');
Run Code Online (Sandbox Code Playgroud)

这是插入函数

        Database db = await this.database;
    var result = await db.insert(category_Table, category.toMap());
    print('category inserted');
        return result;


    }
Run Code Online (Sandbox Code Playgroud)

这是错误

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]})
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助:)

Sil*_*der 7

1)首先检查您在模型中使用的相同变量文本,Map 是否与您的列同名

2)更新数据库版本号

3) 在手机或模拟器上卸载并重新安装该应用程序。