I am trying to create some very basic tables with some foreign keys involved. Although everything else has worked fine so far, I can’t get the table where I have named foreign key to work. I am using IntelliJ IDEA, and essentially what’s happening is it says the parent table cannot be resolved. I have turned on PRAGMA all the way at the top
const db = SQLite.openDatabase('sampleDB.db')
db.exec([{ sql: 'PRAGMA foreign_keys = ON;', args: [] }], false, () =>
console.log('Foreign keys turned on')
);
db.transaction(tx => {
tx.executeSql(`
CREATE TABLE IF NOT EXISTS Profile (
profile_id INTEGER PRIMARY KEY NOT NULL,
username VARCHAR(20) NOT NULL,
height FLOAT,sex VARCHAR NOT NULL,
starting_weight INT,
current_weight FLOAT,
goal_weight FLOAT);
`);
tx.executeSql(`
CREATE TABLE IF NOT EXISTS k (
k_id INTEGER PRIMARY KEY NOT NULL,
profile_id INTEGER,
FOREIGN KEY (profile_id) REFERENCES Profile (profile_id) );
`);
This is how it’s looking:
And this is the same problem with every other table. Any help is greatly appreciated!