Im pretty sure if you say ‘this is a foreign key’ then you need to explain where the key it refers to lives - ie which other table and which other column.
SQLite supports foreign keys, but they are not enabled by default. To enable them, you use the SQLite PRAGMA command each time you connect to the database:
PRAGMA foreign_keys = ON;
You can send this PRAGMA command to SQLite from Xojo using ExecuteSQL:
Var db As New SQLiteDatabase
Try
db.Connect
' Enable foreign keys
db.ExecuteSQL("PRAGMA foreign_keys = ON;")
Catch error As DatabaseException
MessageBox("Database error: " + error.Message)
End Try
Incorrect FOREIGN KEY Syntax
In SQLite, FOREIGN KEY constraints are not specified directly in the column definition with just FOREIGN KEY. You must use REFERENCES to specify which table and column the foreign key relates to.
Missing comma before PRIMARY KEY
There is no comma between the last column definition and the PRIMARY KEY line.
SQLite doesn’t use VARCHAR without a length (though it allows it)
While SQLite allows VARCHAR with no length, it’s more typical to just use TEXT.
Corrected Version for SQLite
CREATE TABLE IF NOT EXISTS SessionPersonnel (
Personnel_ID INTEGER NOT NULL,
Session_ID INTEGER NOT NULL,
SessionPersonnel_RoleInSession TEXT,
PRIMARY KEY (Personnel_ID, Session_ID),
FOREIGN KEY (Personnel_ID) REFERENCES Personnel(ID),
FOREIGN KEY (Session_ID) REFERENCES Session(ID)
);
Make sure that:
You have tables named Personnel and Session with ID as their primary keys.
Foreign key support is enabled in your SQLite database (run PRAGMA foreign_keys = ON;).