Reputation: 1321
I am using sqflite
for database. When I try to create one table it works perfectly. But when I add some additional SQL
code to create extra tables I get this error:
error DatabaseException(near ",": syntax error (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE deletednotes(id INTEGER PRIMARY, title TEXT, description TEXT, priority INTEGER, date int)) sql 'CREATE TABLE deletednotes(id INTEGER PRIMARY, title TEXT, description TEXT, priority INTEGER, date int)' args []} during open, closing...
How can I create multiple tables properly?
Here is my queries:
void _createDB(Database db, int version) async {
await db.execute('''CREATE TABLE $notetable(
$COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TITLE TEXT, $COL_DESCRIPTION TEXT, $COL_PRIORITY INTEGER, $COL_DATE int)''');
await db.execute(
'''CREATE TABLE $archievedtable($COL_ID INTEGER PRIMARY KEY, $COL_TITLE TEXT, $COL_DESCRIPTION TEXT, $COL_PRIORITY INTEGER, $COL_DATE int)''');
await db.execute(
'''CREATE TABLE $deletedtable($COL_ID INTEGER PRIMARY, $COL_TITLE TEXT, $COL_DESCRIPTION TEXT, $COL_PRIORITY INTEGER, $COL_DATE int)''');
}
There can be some syntax errors maybe, any ideas?
static const COL_TITLE = "title";
static const COL_DESCRIPTION = "description";
static const COL_PRIORITY = "priority";
static const COL_DATE = "date";
String notetable = "notes";
String deletedtable = "deletednotes";
String archievedtable = "archievednotes";```
Upvotes: 0
Views: 362
Reputation: 899
Replace int
in your sql code with INTEGER
and change the following
line to add the keyword KEY
after declaring the primary key:
await db.execute(
'''CREATE TABLE $deletedtable($COL_ID INTEGER PRIMARY, $COL_TITLE TEXT, $COL_DESCRIPTION TEXT, $COL_PRIORITY INTEGER, $COL_DATE int)''');
.
To:
await db.execute(
'''CREATE TABLE $deletedtable($COL_ID INTEGER PRIMARY KEY, $COL_TITLE TEXT, $COL_DESCRIPTION TEXT, $COL_PRIORITY INTEGER, $COL_DATE int)''');
Upvotes: 1