mysql 数据库异常(数据库异常(靠近“自动增量”:语法错误(代码1 SQLITE_ERROR):,编译时:创建表格注解

eimct9ow  于 2023-01-25  发布在  Mysql
关注(0)|答案(1)|浏览(195)

错误

Exception has occurred.
SqfliteDatabaseException (DatabaseException(near "AUTOINCREMENT": syntax error (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE notlar(
      id INTEGER AUTOINCREMENT NOT NULL PRIMARY KEY,
      onenote TEXT NOT NULL
    )) sql '    CREATE TABLE notlar(
      id INTEGER AUTOINCREMENT NOT NULL PRIMARY KEY,
      onenote TEXT NOT NULL
    )
    ' args [])

这是我用flutter包sqflite创建表的代码。我有readData,deleteData,updateData和insertData函数。但是我得到了错误。有很多选项可以解决这个问题,但是我没有解决这个问题。我尝试了很多选项来解决。

class SqlDb {
  static Database? _db;

  Future<Database?> get db async {
    if (_db == null) {
      _db = await initialDb();
      return _db;
    } else {
      return _db;
    }
  }

  initialDb() async {
    String databasePath = await getDatabasesPath();
    String path = join(databasePath, 'wael.db');
    Database mydb = await openDatabase(path,
        onCreate: _onCreate, version: 2, onUpgrade: _onUpgrade);
    return mydb;
  }

   _onUpgrade(Database db, int oldVersion, int newVersion) {
    print("ronaldo");
  }

  _onCreate(Database db, int version) async {
    await db.execute('''
    CREATE TABLE notlar(
      id INTEGER AUTOINCREMENT NOT NULL PRIMARY KEY,
      onenote TEXT NOT NULL
    )
    ''');
    print("created database and table");
  }

  

  readData(String sql) async {
    Database? mydb = await db;
    List<Map> response = await mydb!.rawQuery(sql);
    return response;
  }

  insertData(String sql) async {
    Database? mydb = await db;
    int response = await mydb!.rawInsert(sql);
    return response;
  }

  updateData(String sql) async {
    Database? mydb = await db;
    int response = await mydb!.rawUpdate(sql);
    return response;
  }

  deleteData(String sql) async {
    Database? mydb = await db;
    int response = await mydb!.rawDelete(sql);
    return response;
  }
}
2vuwiymt

2vuwiymt1#

您是否尝试过将AUTOINCREMENT关键字移到主键之后?
参考:包github问题

相关问题