Django中遇到的问题以及解决方法

本文详细列举了在使用Django过程中遇到的各种错误及解决方法,包括SQLite版本不匹配、_sqlite3模块缺失、Django项目无法直接运行、makemigrations错误、CSRF cookie问题、pip安装模块时的网络问题、mysqlclient版本不兼容、URL路径问题、MySQLdb导入错误等,并提供了相应的解决方案。
摘要由CSDN通过智能技术生成

文章目录

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 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值