Using foreign keys in sqlite3 for Python

后端 未结 3 545
孤独总比滥情好
孤独总比滥情好 2021-02-12 23:24

I\'m writing a program that creates a sqlite3 database through python. I have one table of Authors (AuthorID, Name) and a second table of books (BookID, Title, AuthorID) I\'ve c

3条回答
  •  清歌不尽
    2021-02-13 00:05

    The PRAGMA foreign_keys setting applies to a connection, so you should execute it immediately after calling sqlite3.connect().

    Please note that foreign key constraints work only inside the same database; you should put both tables into the same file.

提交回复
热议问题