django sqlite3 报错问题

sqlite3 报错问题

  • 报错
raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

就是Django查到的Sqlite的版本不对,找到的是3.7.17,
但是对版本要求(version <= 3.8.3),爬了一下资料,
在Django版本说明中看到

# SQLite的最低支持版本从3.7.15增加到3.8.3
The minimum supported version of SQLite is increased from 3.7.15 to 3.8.3.
这就得升级Sqlite3的版本了

下载

Sqlite 下载官网
Sqlite 3.28.0

选择需要的版本下载Source Code -> sqlite-autoconf*

安装

# 下载
wget http://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz

# 解包
tar -zxvf sqlite-autoconf-3280000.tar.gz

# 进入目录
cd sqlite-autoconf-3280000

# 配置 
./configure 
# --prefix=/usr/local 预安装目录(可选)

# 编译
make && sudo make install
# 等待编译完成即可,如果没有什么其他的报错,应该就OK的。

测试
如果是Centos7,yum更新了最新的Sqlite,默认的版本应该是3.7.17,

# 备份默认的sqlite
sudo mv -v /usr/bin/sqlite3 /usr/bin/sqlite3.7.17

# "/usr/bin/sqlite3" -> "/usr/bin/sqlite3.7.17"

# 复制新版本的sqlite文件夹
# 此时目录 sqlite-autoconf-3280000
sudo cp -v sqlite3 /usr/bin 

# "sqlite3" -> "/usr/bin/sqlite3"

# 查看一下文件是否成功
ls /usr/bin |grep sqlite

# sqlite3
# sqlite3.7.17

# 共享库
export LD_LIBRARY_PATH="/usr/local/lib"
# 如果登出后失效的,可以写进~/.bashrc 或 ~/.bash_profile

使用

# 版本查看
sqlite3 --version
# 3.28.0 2019-04-16 19:49:53
# 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50


# Python调用Sqlite版本查看
python3.6

Python 3.6.8 (default, Apr 16 2019, 14:31:25) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.28.0'
>>> exit()

# 运行Django
python3.6 manage.py

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[auth]
    changepassword
    createsuperuser

[contenttypes]
    remove_stale_contenttypes
...

正常了,没有版本不匹配的报错了。
其实主要sqlite3是yum源的最新版本才3.7.17,别卸载它后再装(跳过坑),yum依赖sqlite,所以只有编译安装或者其他方式安装后替换文件目录。

另外要注意的是,sudo python3.6 & python3.6的执行结果是不同的。

原文地址:https://www.cnblogs.com/iFanLiwei/p/12873399.html