diff --git a/database.py b/database.py index d39a95b..383e566 100644 --- a/database.py +++ b/database.py @@ -39,6 +39,7 @@ def add_user(db, *, username, password, email, parent, status): # Add the user into the database cursor = db.cursor() + cursor.execute('PRAGMA foreign_keys = ON;') # Fail if we insert a user with bogus parent field cursor.execute('INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?);', (userid, parent, status, password, username, email, '')) def initialize_users(db, admin_user, admin_password): @@ -58,7 +59,9 @@ def initialize_users(db, admin_user, admin_password): username text NOT NULL, email text NOT NULL, - comment text NOT NULL + comment text NOT NULL, + + FOREIGN KEY(parent) REFERENCES users(id) );''') add_user(db, username = admin_user, password = admin_password, email = '', parent = None, status = userstatus.admin)