错误
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;
}
}
1条答案
按热度按时间2vuwiymt1#
您是否尝试过将
AUTOINCREMENT
关键字移到主键之后?参考:包github问题