I need the fix the problem when I put all information and click save > > there's nothing on the database
0
I need the fix the problem when I put all information and click save there's nothing on the database
Error:
E/flutter (12919): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: DatabaseException(table PERSON has no column named salary (code 1 SQLITE_ERROR): ,
Error:
E/flutter (12919): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: DatabaseException(table PERSON has no column named salary (code 1 SQLITE_ERROR):
litedb.dart:
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
class LiteDb {
static Database? _db;
Future<Database?> get getInstance async {
if (_db == null) {
_db = await instance();
return _db;
} else {
return _db;
}
}
instance() async {
// Get a location using getDatabasesPath
var databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'lite_sql.db');
// open the database
Database database = await openDatabase(path, version: 2,
onCreate: (Database db, int version) async {
// When creating the db, create the table
await db.execute(
'''
CREATE TABLE PERSON (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER);
CREATE TABLE ACCOUNT (id INTEGER PRIMARY KEY AUTOINCREMENT, PERSON_ID INTEGER NOT NULL, ACCOUNT INTEGER NOT NULL, VALUE REAL);
''');
print('Text Database has been created');
},
onUpgrade: (Database db, int oldVersion, int newVersion) async {
if (newVersion >= 2) {
await db.execute('''
ALTER TABLE PERSON ADD COLUMN salary REAL NULL
''');
}
}
);
print(' Database connected');
return database;
}
inquiry(String sqlTxt) async {
Database? db = await getInstance;
// Get the records
List<Map> list = await db!.rawQuery(sqlTxt);
return list;
}
insert(String sqlTxt) async {
Database? db = await getInstance;
// Insert some record
int count = await db!.rawInsert(sqlTxt);
return count;
}
update(String sqlTxt) async {
Database? db = await getInstance;
// Update some record
int count = await db!.rawUpdate(sqlTxt);
return count;
}
delete(String sqlTxt) async {
Database? db = await getInstance;
// Delete some record
int count = await db!.rawDelete(sqlTxt);
return count;
}
}
I need help please?????