[root@localhost mysite]# python3 manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "
File "
File "
File "
File "
File "
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in
class AbstractBaseUser(models.Model):
File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python3.6/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 "/usr/local/lib/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 66, in
check_sqlite_version()
File "/usr/local/lib/python3.6/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).
重点发现错误提示:
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
django发现Python使用的sqlite版本过低,不满足要求。因此,我尝试升级自带的sqlite。使用sqlite3 –version查看了CentOS的Sqlite为3.7
可以通过找到django安装在哪些路径下,在我的系统上,需要找到/…/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py这个脚本,django判断当前使用的sqlite版本的代码就在这里,找到以下代码块全部注释掉如下:
再次实行: python3 manage.py runserver 已经成功跑起来
解决方法二:升级sqlite3
1. 系统默认的sqlite3版本:
[root@mysql ~]# /usr/bin/sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
2. 安装sqlite3最新版SQLite 3.8.3
[root@mysql ~]# wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
[root@mysql ~]# tar -zxvf sqlite-autoconf-3270200.tar.gz
[root@mysql ~]# cd sqlite-autoconf-3270200
[root@mysql sqlite-autoconf-3270200]# make && make install
3. 删除文件夹及安装包
[root@mysql ~]# rm -rf sqlite-autoconf-3270200 sqlite-autoconf-3270200.tar.gz
4. 检查安装版本
新版本
[root@mysql ~]# /usr/local/bin/sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
旧版本
[root@mysql ~]# /usr/bin/sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
5. 更新sqlite3
[root@mysql ~]# mv /usr/bin/sqlite3 /usr/bin/sqlite3_3.7.17
[root@mysql ~]# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
[root@mysql ~]# /usr/bin/sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
6. 也可写入本地环境文件.bashrc,生效:
export LD_LIBRARY_PATH="/usr/local/lib"