Enabling JSON1 extension on SQLite

To use django.db.models.JSONField on SQLite, you need to enable thJSON1 extension on Pythons sqlite3 library. If the extension is not enabled on your installation, a system error (fields.E180) will be raised. To check if the extension is enabled on your installation, you can do a query with one of the functions included in the extension, e.g. JSON(). For example:

>>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> cursor = conn.cursor()
>>> cursor.execute('SELECT JSON('{"a": "b"}')')

If the query doesn‘t throw any errors, then the JSON1 extension is already enabled. Otherwise, follow the instructions below according to your operating system to set it up correctly.

Linux

On most major Linux distributions, the JSON1 extension is included in their SQLite and/or Python packages and enabled by default. If that’s not the case on your installation, then do the following:

macOS

As of Python 3.7, the official Python installer on macOS already includes the JSON1 extension by default. If you’re using an earlier version of Python or unofficial installers, you can follow the instructions for Linux above, but instead of setting the LD_PRELOAD environment variable, use DYLD_LIBRARY_PATH. For example:

export DYLD_LIBRARY_PATH=/usr/lib/sqlite3

Windows

As of Python 3.9, the official Python installer on Windows already includes the JSON1 extension by default. If you’re using an earlier version of Python or unofficial installers, you can do the following:

原文地址:https://blog.csdn.net/weixin_41216652/article/details/126950042

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_13201.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注