安装 GreaterWMS,启动Django时,报错:
/usr/local/bin/daphne -p 8008 greaterwms.asgi:application
提示:
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17)
解决办法:
1、查看当前SQLite3版本:
# sqlite3 --version 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
2、下载最新版的sqlite3
下载地址:https://www.sqlite.org/download.html
3、安装sqlite3
cd /alidata/tmp wget -c https://www.sqlite.org/2022/sqlite-autoconf-3380000.tar.gz tar -xzvf sqlite-autoconf-3380000.tar.gz cd sqlite-autoconf-3380000 ./configure --prefix=/usr/local make && make install
4、检测安装
# /usr/local/bin/sqlite3 --version 3.38.0 2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab
5、更改链接
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
6、运行环境的sqlite3版本
# sqlite3 --version 3.38.0 2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab
7、将路径传递给共享库【很重要】
在配置文件 /etc/profile
文件中,追加以下文本:
export LD_LIBRARY_PATH="/usr/local/lib"
使修改生效:
source /etc/profile
8、检查Python的SQLite3版本
# python3 Python 3.9.10 (main, Mar 11 2022, 04:14:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> sqlite3.sqlite_version '3.38.0' >>> exit()
9、执行项目
# /usr/local/bin/daphne -p 8008 greaterwms.asgi:application Welcome To GreaterWMS 2022-03-12 00:12:38,759 INFO Starting server at tcp:port=8008:interface=127.0.0.1 2022-03-12 00:12:38,759 INFO HTTP/2 support enabled 2022-03-12 00:12:38,760 INFO Configuring endpoint tcp:port=8008:interface=127.0.0.1 2022-03-12 00:12:38,761 INFO Listening on TCP address 127.0.0.1:8008
继续执行 命令:
# python3 manage.py makemigrations
报错:
django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 200, in connect self.connection = self.get_new_connection(conn_params) File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 215, in get_new_connection create_deterministic_function('django_date_extract', 2, _sqlite_datetime_extract) django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
解决方案:
升级之后由一个不能被支持的参数引发NotSupportError
,说明django虽然获取到了>=3.8.3版本的sqlite,但是部分方法仍然不能支持新特性。
如此这般,只能走另外一条途径解决问题。不依赖系统提供的sqlite3 使用 pysqlite3
和 pysqlite3-binary
库来操作。首先需要安装这两个库
pip3 install pysqlite3 pip3 install pysqlite3-binary
修改db代码导入库
# vim /usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py
修改内容:第14行
# from sqlite3 import dbapi2 as Database (注释掉这段) from pysqlite3 import dbapi2 as Database # 启用pysqlite3 # :wq 保存即可
修改后,执行成功:
# python3 manage.py makemigrations Welcome To GreaterWMS Migrations for 'asn': asn/migrations/0001_initial.py - Create model AsnDetailModel - Create model AsnListModel