文章目录
1. SQLite 3.8.3 or later is required (found 3.7.17)
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版本降级
- 卸载当前的django版本:[root@instance-mtfsf05r mysite]# pip3 uninstall django
- 安装一个版本低一些的:[root@instance-mtfsf05r mysite]# pip3 install django==2.1.12
② 安装SQLite 3.8.3或以上的版本
【SQLite官网】:https://www.sqlite.org/download.html
-
下载SQLite3源码安装包:[root@instance-mtfsf05r ~]# wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
-
解压缩:[root@instance-mtfsf05r ~]# tar -zxvf sqlite-autoconf-3290000.tar.gz
-
切换到sqlite目录下:[root@instance-mtfsf05r ~]# cd sqlite-autoconf-3290000/
-
释放编译文件:[root@instance-mtfsf05r sqlite-autoconf-3290000]# ./configure --prefix=/usr/local/sqlit329
-
编译和安装[root@instance-mtfsf05r sqlite-autoconf-3290000]# make && make install
-
查看当前全局sqlite3的版本检查sqlite3版本还是没有被改变,所以更改旧的sqlite3:
[root@instance-mtfsf05r ~]# sqlite3 -version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
[root@instance-mtfsf05r ~]# mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
-
为新版本创建软链接:[root@instance-mtfsf05r ~]# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
-
检查当前SQLite3版本:[root@instance-mtfsf05r ~]# sqlite3 --version
-
检查Python的SQLite3版本:[root@instance-mtfsf05r ~]# python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.29.0'
再次运行django项目:
2. ModuleNotFoundError: No module named ‘_sqlite3’
错误场景:运行Django项目的时候报错,找不到_sqlite3模块
问题原因:因为安装python3的时候没有找到安装sqlite3依赖
解决方式:安装这个模块,然后编译安装python3
[root@instance-mtfsf05r Python-3.7.3]# yum install sqlite*
[root@instance-mtfsf05r Python-3.7.3]# make && make install
ps:在重新编译安装python的时候,需要安装一些依赖,下面是安装python的依赖:
[root@VM_39_157_centos ~]# yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
3. 导入的django项目不能至直接运行
解决方式:
1、第一步
2、第二步
4. 执行python3 manage.py makemigrations
执行python3 manage.py makemigrations报下面的错误:
You are trying to add a non-nullable field 'goods' to order without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option:
执行python3 manage.py migrate报下面的错误:
Operations to perform:
Apply all migrations: admin, app, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
解决方式:thanlon@vivobook:~/git与gitee项目/github/alipay_django/app/migrations$ rm -rf 0001_initial.py
makemigrations 命令用于将定义的模型生成 0001_initial.py 文件,0001_initial.py中是生成数据表的脚本代码,migrate命令根据脚本呢代码在目标数据库中生成相对于的数据表。第一次创建过数据表,再次创建就会报上面的错误。
5. Forbidden (CSRF cookie not set.)
问题原因:CSRF cookie not set.这里使用了中间件,可以把CSRF中间件注释掉
解决方案:注释掉 django.middleware.csrf.CsrfViewMiddleware
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
6. pip安装模块出现连接问题
问题原因: 国外资源,访问比较慢
解决方案: 指定清华源或者豆瓣源下载,清华源:https://pypi.tuna.tsinghua.edu.cn/simple,豆瓣源:,使用的格式:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 模块名
pip install -i https://pypi.douban.com/simple 模块名
PS:我的站点:https://www.blueflags.cn
技术交流加微信: