I can't get my program to use a foreign key for some unbeknown reason. I have read other questions related to this but cant find an answer that works. I tried the PRAGMA foreign_keys = ON, but instead i get a syntax error for "foreign_keys". I also tried removing this and running the program again and instead got an error saying the column I'm trying to create doesn't exist
import sqlite3
import os
import random
from tkinter import *
import uuid
PRAGMA foreign_keys = ON
conn = sqlite3.connect('MyComputerScience.db')
c = conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS users (
UserID text PRIMARY KEY,
FName text,
SName text,
username text,
password varchar,
userType text)""")
c.execute("""CREATE TABLE IF NOT EXISTS classes (
ClassID PRIMARY KEY,
FOREIGN KEY (User) REFERENCES users(UserID)))""")
FOREIGN KEY (User) REFERENCES users(UserID)))""")
sqlite3.OperationalError: unknown column "User" in foreign key definition
conn.execute("PRAGMA foreign_keys = on")). See this answer: stackoverflow.com/a/29427284/1441112