21👍
✅
Add this code in the __init__.py
file of one of your installed app:
from django.db.backends.signals import connection_created
def activate_foreign_keys(sender, connection, **kwargs):
"""Enable integrity constraint with sqlite."""
if connection.vendor == 'sqlite':
cursor = connection.cursor()
cursor.execute('PRAGMA foreign_keys = ON;')
connection_created.connect(activate_foreign_keys)
0👍
The article suggests that you add that as a middleware (at the very end). That middleware is then configured as a string inside settings.py, so you shouldn’t get any import conflicts.
- Django – How can you include annotated results in a serialized QuerySet?
- Django WeasyPrint CSS integration warning: Relative URI reference without a base URI: <link href="/static/css/bootstrap.min.css"> at line None
- Django doesn't create translation .po files
- How to pass the remote IP to a proxied service? – Nginx
- How to format django template in Sublime Text
Source:stackexchange.com