使用django3.X版本在centos7系統(tǒng)運(yùn)行拋錯(cuò)
# [django can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))](https://stackoverflow.com/questions/55674176/django-cant-find-new-sqlite-version-sqlite-3-8-3-or-later-is-required-found)
剛剛開(kāi)始拋當(dāng)前版本不支持。我升級(jí)sqlite3的版本后事甜,驗(yàn)證了 sqlite3 的版本為我安裝的版本兔沃。也驗(yàn)證了python3中導(dǎo)入的 sqlite3 版本 也是我安裝的版本玛迄。繼續(xù)運(yùn)行django項(xiàng)目, 繼續(xù)拋以下錯(cuò)誤:
"/usr/local/python3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py" 602L, 25741C written
fn(*args, **kwargs)
File "/usr/local/python3/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check_migrations()
File "/usr/local/python3/lib/python3.8/site-packages/django/core/management/base.py", line 459, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/usr/local/python3/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/python3/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/usr/local/python3/lib/python3.8/site-packages/django/db/migrations/loader.py", line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/python3/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/usr/local/python3/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/usr/local/python3/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/python3/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/usr/local/python3/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/usr/local/python3/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/python3/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/python3/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/python3/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/python3/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/python3/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/python3/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/python3/lib/python3.8/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
以為是動(dòng)態(tài)鏈接庫(kù)沒(méi)有更新 又重新安裝了一把python3.8宁舰、發(fā)現(xiàn)結(jié)果還是一樣不能運(yùn)行成功
升級(jí)之后由一個(gè)不能被支持的參數(shù)引發(fā)NotSupportError拼卵,說(shuō)明django雖然獲取到了>=3.8.3版本的sqlite,但是部分方法仍然不能支持新特性蛮艰、
如此這般腋腮,只能走另外一條途徑解決問(wèn)題。不依賴(lài)系統(tǒng)提供的sqlite3 使用 pysqlite3
和 pysqlite3-binary
庫(kù)來(lái)操作印荔。首先需要安裝這兩個(gè)庫(kù)
pip3 install pysqlite3
pip3 install pysqlite3-binary
修改db代碼導(dǎo)入庫(kù)
vi /usr/local/python3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py
# 修改內(nèi)容
# from sqlite3 import dbapi2 as Database (注釋掉這段)
from pysqlite3 import dbapi2 as Database # 啟用pysqlite3
# :wq 保存即可
然后可運(yùn)行 python3 manage.py runserver 即成功運(yùn)行