conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute("INSERT INTO child VALUES(NULL, 'bobby')")
bobby_id = c.lastrowid
c.execute("INSERT INTO dog VALUES(NULL, 'spot')")
spot_id = c.lastrowid
c.execute('INSERT INTO child_dog VALUES(?, ?)', (bobby_id, spot_id))
conn.commit()
conn.close()
Примеры внешнего ключа SQLite