• (fields.E180) SQLite does not support JSONFields.


    Enabling JSON1 extension on SQLite

    To use django.db.models.JSONField on SQLite, you need to enable the JSON1 extension on Python's 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:

    • Download the SQLite amalgamation, with or without the configuration script.

    • Extract the source code archive and enter the directory of the result.

    • Compile the source code using the -DSQLITE_ENABLE_JSON1 flag to enable the JSON1 extension. For example:

      gcc -DSQLITE_ENABLE_JSON1 -c -fPIC sqlite3.c
      

      To enable other extensions, see the compilation instructions.

    • Create a shared library. For example:

      gcc -shared -o libsqlite3.so -fPIC sqlite3.o -ldl -lpthread
      
    • Place the resulting file (libsqlite3.so) in a desired directory, e.g. /usr/lib/sqlite3/.

    • Set the LD_PRELOAD environment variable to use your compiled SQLite every time you run Django. For example:

      export LD_PRELOAD=/usr/lib/sqlite3/libsqlite3.so
      
    • Now, the JSON1 extension should be ready to be used in Python and Django.

    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:

    • Download the precompiled DLL that matches your Python installation (32-bit or 64-bit).
    • Locate your Python installation. By default, it should be in %localappdata%\Programs\Python\PythonXX, where XX is the Python version. For example, it's located in C:\Users\\AppData\Local\Programs\Python\Python37. If you added Python installation directory to your PATH environment variable, you can run the command where python on a command prompt to locate it.
    • Enter the DLLs directory in your Python installation.
    • Rename (or delete) sqlite3.dll inside the DLLs directory.
    • Extract sqlite3.dll from the downloaded DLL archive and put it in the DLLs directory.
    • Now, the JSON1 extension should be ready to be used in Python and Django.
  • 相关阅读:
    从数据的属性看数据资产
    SpringBoot-快速搭建并快速验证是否可用
    Powerbi-矩阵日期表&矩阵列数据表头排序
    sklearn 基础教程
    SQL教学: MySQL进阶操作详解--探索DML语句的高级用法
    前端远程调试方案 Chii 的使用经验分享
    【uniapp】小程序开发6:自定义状态栏
    3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
    ActiveMQ、RabbitMQ、RocketMQ、Kafka区别
    C#基础语法--变量
  • 原文地址:https://blog.csdn.net/weixin_41216652/article/details/126950042