Guest User

init_db

a guest
Jul 14th, 2025
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import sqlite3
  2.  
  3. # Connect to DB with autocommit mode
  4. conn = sqlite3.connect("meal_ingredients.db", isolation_level=None)
  5.  
  6. # Ensure tables exist
  7. conn.execute("PRAGMA foreign_keys = ON")
  8. conn.execute("CREATE TABLE IF NOT EXISTS meals (name TEXT) STRICT")
  9. conn.execute(
  10. """
  11. CREATE TABLE IF NOT EXISTS ingredients (
  12. name TEXT,
  13. meal_id INTEGER,
  14. FOREIGN KEY(meal_id) REFERENCES meals(rowid)
  15. ) STRICT
  16. """
  17. )
  18.  
  19. res = conn.execute("SELECT * FROM sqlite_schema WHERE name = 'meals'").fetchone()
  20. print(res)
Advertisement
Add Comment
Please, Sign In to add comment