在Django 2 2中啓動開發服務器時處理SQLite3錯誤

報錯信息

python3 manage.py runserver啓動django項目的時候,就會出現報錯信息以下: django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).python

查看系統的sqlte3的版本

[root@djangoServer work]# sqlite3 --version 
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
[root@djangoServer work]# 
複製代碼

果真Centos系統自帶的sqlite3版本偏低,在上面的錯誤提示中要求須要SQLite 3.8.3 or later,那麼就須要去升級 SQlite 的版本了。sql

Centos7安裝最新的sqlite3並設置更新python庫版本

#更新SQLite 3
#獲取源代碼(在主目錄中運行)
[root@djangoServer ~]# cd ~
[root@djangoServer ~]# wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
[root@djangoServer ~]# tar -zxvf sqlite-autoconf-3270200.tar.gz

#構建並安裝
[root@djangoServer ~]# cd sqlite-autoconf-3270200
[root@djangoServer sqlite-autoconf-3270200]# ./configure --prefix=/usr/local
[root@djangoServer sqlite-autoconf-3270200]# make && make install
[root@djangoServer sqlite-autoconf-3270200]# find /usr/ -name sqlite3
/usr/bin/sqlite3
/usr/lib64/python2.7/sqlite3
/usr/local/bin/sqlite3
/usr/local/python3/lib/python3.7/site-packages/django/db/backends/sqlite3
/usr/local/python3/lib/python3.7/sqlite3
[root@djangoServer sqlite-autoconf-3270200]# 

#沒必要要的文件,目錄刪除
[root@djangoServer sqlite-autoconf-3270200]# cd ~
[root@djangoServer ~]# ls
anaconda-ks.cfg  sqlite-autoconf-3270200  sqlite-autoconf-3270200.tar.gz
[root@djangoServer ~]# 
[root@djangoServer ~]# rm -rf sqlite-autoconf-3270200.tar.gz
[root@djangoServer ~]# rm -rf sqlite-autoconf-3270200

#檢查版本
## 最新安裝的sqlite3版本
[root@djangoServer ~]# /usr/local/bin/sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
[root@djangoServer ~]# 

## Centos7自帶的sqlite3版本
[root@djangoServer ~]# /usr/bin/sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
[root@djangoServer ~]# 

## 能夠看到sqlite3的版本仍是舊版本,那麼須要更新一下。
[root@djangoServer ~]# sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
[root@djangoServer ~]# 

## 更改舊的sqlite3
[root@djangoServer ~]# mv /usr/bin/sqlite3 /usr/bin/sqlite3_old

## 軟連接將新的sqlite3設置到/usr/bin目錄下
[root@djangoServer ~]# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3

## 查看當前全局sqlite3的版本
[root@djangoServer ~]# sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
[root@djangoServer ~]# 

#將路徑傳遞給共享庫
# 設置開機自啓動執行,能夠將下面的export語句寫入 ~/.bashrc 文件中,若是若是你想當即生效,能夠執行source 〜/.bashrc 將在每次啓動終端時執行
[root@djangoServer ~]# export LD_LIBRARY_PATH="/usr/local/lib"

#檢查Python的SQLite3版本
[root@djangoServer ~]# ipython3
Python 3.7.1 (default, May  3 2019, 09:55:04) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sqlite3                                                     

In [2]: sqlite3.sqlite_version                                             
Out[2]: '3.27.2'

In [3]: exit                                                               
[root@djangoServer ~]# 

#啓動開發服務器
[root@djangoServer ~]# cd /work/
[root@djangoServer work]# ls
db.sqlite3  manage.py  polls  test_django
[root@djangoServer work]# python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
May 03, 2019 - 21:32:28
Django version 2.2.1, using settings 'test_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
複製代碼

相關文章
相關標籤/搜索