The error
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 [])
This is my code for create the table with flutter package sqflite. I have readData, deleteData, updateData and insertData functions for table. But I am getting error. There are a lot of options to solve the problem but I don't solve the problem. I tried a lot of options to solve.
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;
}
}
CodePudding user response:
Have you tried moving the AUTOINCREMENT
keyword after the primary key? Like id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
Reference: package github issue