Syntax Error In Sqlite Query While Adding Foreign Key
I got syntax error in my sqlite query while executing the query db.execSQL('CREATE TABLE '+TABLE_ABC+' (ID INTEGER PRIMARY KEY AUTOINCREMENT, EVENT_MATCH_ID INTEGER, FOREIGN KEY
Solution 1:
Put your table constraints such as foreign key definitions after the column specifications:
db.execSQL("CREATE TABLE "+TABLE_ABC+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, EVENT_MATCH_ID INTEGER, EVENT_ID TEXT, EVENT_TYPE TEXT, EVENT_MINUTE TEXT," +
"EVENT_TEAM TEXT, EVENT_PLAYER TEXT, EVENT_PLAYER_ID TEXT, EVENT_RESULT TEXT, " +
"FOREIGN KEY (EVENT_MATCH_ID) REFERENCES "+TABLE_DEF+" (MATCH_ID))");
Solution 2:
The table constraints go after the column definition:https://www.sqlite.org/lang_createtable.html
Try this:
db.execSQL("CREATE TABLE "+TABLE_ABC+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, EVENT_MATCH_ID INTEGER, EVENT_ID TEXT, EVENT_TYPE TEXT, EVENT_MINUTE TEXT," +
"EVENT_TEAM TEXT, EVENT_PLAYER TEXT, EVENT_PLAYER_ID TEXT, EVENT_RESULT TEXT, " +
"FOREIGN KEY (EVENT_MATCH_ID) REFERENCES "+TABLE_DEF+" (MATCH_ID))");
Solution 3:
Plz try this:
db.execSQL("CREATE TABLE "+TABLE_ABC+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, EVENT_MATCH_ID INTEGER, EVENT_ID TEXT, EVENT_TYPE TEXT, EVENT_MINUTE TEXT," +
"EVENT_TEAM TEXT, EVENT_PLAYER TEXT, EVENT_PLAYER_ID TEXT, EVENT_RESULT TEXT, FOREIGN KEY (EVENT_MATCH_ID) REFERENCES "+TABLE_DEF+" (MATCH_ID))");
Post a Comment for "Syntax Error In Sqlite Query While Adding Foreign Key"