0

I've designed a database structure where I want to use foreign keys to link several tables, but I'm not sure how to do it with phpLiteAdmin.

I searched other posts and got an error "ERROR: near "db": syntax error" when I tried "db.execute("PRAGMA foreign_keys = ON")". I am not sure where to put this db.execute (in the database or the table - tried both) or whether the program even has foreign key capability.

Please help and let me know whether and how I can use foreign keys.

1 Answer 1

1

sqlite3 on cs50 does have foreign key capabilities. If you want to enforce foreign key constraints in phpLiteAdmin (or sqlite3), the command is simply PRAGMA foreign_keys = ON;. You would only use db.execute("PRAGMA foreign_keys = ON"); in python (execute is a method of a SQL object). Foreign key support must be turned "on" for every database connection, so the db.execute would probably go right after db is instantiated in application.py.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .