Why aren't my sqlite3 foreign keys working?

前端 未结 2 1120
我寻月下人不归
我寻月下人不归 2021-01-05 07:58

I run the following code from a python interpreter, and expect the insert statement to fail and throw some kind of exception. But it\'s not happening:

Python         


        
2条回答
  •  [愿得一人]
    2021-01-05 08:13

    As said by Nicholas, check if your version of sqlite has foreign key support. This doesn't matter if the version of sqlite greater than or equal to 3.6.19. The source may be compiled with foreign key support turned off. To check execute the following command.

    cursor.execute("PRAGMA foreign_keys")

    If it does not return any data then your version has no foreign key support.

    NB: Foreign key support is not enforced in sqlite3 as of now. Check out here.

提交回复
热议问题