Enable integrity checking with sqlite in django

前端 未结 2 1067
天命终不由人
天命终不由人 2020-12-16 20:27

In my django project, I use mysql db for production, and sqlite for tests.

Problem is, some of my code rely on model integrity checking. It works well with mysql, bu

2条回答
  •  一向
    一向 (楼主)
    2020-12-16 21:10

    You could use django signals, listening to post_syncdb.

    from django.db.models.signals import post_syncdb
    
    def set_pragma_on(sender, **kwargs):
        "your code here"
    
    post_syncdb.connect(set_pragma_on)
    

    This ensures that whenever syncdb is run (syncdb is run, when creating the test database), that your SQLite database has set 'pragma' to 'on'. You should check which database you are using in the above method 'set_pragma_on'.

提交回复
热议问题