signed

QiShunwang

“诚信为本、客户至上”

django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

2021/4/26 17:26:56   来源:

新建Django项目的app出现如下错误:

(env) [root@VM-0-5-centos apiproject]# python manage.py startapp blog
Traceback (most recent call last):
  File "/home/Django/apiproject/manage.py", line 22, in <module>
    main()
  File "/home/Django/apiproject/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/Django/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/Django/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/home/Django/env/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/Django/env/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/Django/env/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/python3/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/Django/env/lib/python3.9/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/Django/env/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/Django/env/lib/python3.9/site-packages/django/db/models/base.py", line 117, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/home/Django/env/lib/python3.9/site-packages/django/db/models/base.py", line 321, in add_to_class
    value.contribute_to_class(cls, name)
  File "/home/Django/env/lib/python3.9/site-packages/django/db/models/options.py", line 204, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/home/Django/env/lib/python3.9/site-packages/django/db/__init__.py", line 28, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/home/Django/env/lib/python3.9/site-packages/django/db/utils.py", line 201, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/home/Django/env/lib/python3.9/site-packages/django/db/utils.py", line 110, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/local/python3/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/Django/env/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 66, in <module>
    check_sqlite_version()
  File "/home/Django/env/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 63, in check_sqlite_version
    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).

原因是版本不匹配:Django3需要SQLite 3.8.3或更高版本,而现在的版本为3.7.17

# 查看sqllite版本
(env) [root@VM-0-5-centos Django]# sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668

解决方法:
==法一:降级django版本到2.1。开发环境慎用。 ==

pip3 uninstall django
pip3 install django==2.1.* 

法二:升级sqllite

(env) [root@VM-0-5-centos apiproject]# wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
(env) [root@VM-0-5-centos apiproject]# tar zxvf sqlite-autoconf-3280000.tar.gz
(env) [root@VM-0-5-centos apiproject]# cd sqlite-autoconf-3300100/
(env) [root@VM-0-5-centos sqlite-autoconf-3280000]#./configure
(env) [root@VM-0-5-centos sqlite-autoconf-3280000]# make & make install

# 检查是否安装到最新版本。
(env) [root@VM-0-5-centos sqlite-autoconf-3280000]# python
>>> import sqlite3
>>> sqlite3.sqlite_version # 可以看到已经是要求的3.7.17版本
'3.7.17'

完。