关于django项目配置数据库迁移的一些错误

把django项目git clone后本地pycharm运行总是很多东西需要配置,感觉可能在项目弄个虚拟环境就最方便了,即项目下的venv文件夹。(能力有限,设置不好还是会运行到本地的python或Anaconda3的资源。

经常出问题的一定就是数据库了,不同环境下mysql数据库的配置基本不一样呢。

执行 python manage.py makemigrations报错:

1. 缺少module

ModuleNotFoundError: No module named 'pymysql'

解决:直接pip install pymysql即可
在这里插入图片描述

2. mysqlclient版本不符合

  File "D:\SOFTWARE\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py",line 36, in <module>
    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__) 
 django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

在这里插入图片描述
解决:将提示目录的base.py文件对应行注释掉
在这里插入图片描述

3. ‘str’ object has no attribute ‘decode’

  File "D:\SOFTWARE\Anaconda3\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
    query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'

在这里插入图片描述
str通过encode()编码变成byte,反之decode()译码

解决:将提示目录的operations.py文件对应的decode改为encode
在这里插入图片描述

4.数据库安全模式

D:\SOFTWARE\Anaconda3\lib\site-packages\pymysql\cursors.py:170: Warning: (3135, "'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.")
  result = self._query(query)
No changes detected

在这里插入图片描述
解决:把项目的settings.py关于数据的option注释掉
在这里插入图片描述

其他

  1. 某些问题下,数据库迁移不成功可以把迁移文件删掉重新迁移
    在这里插入图片描述
  2. 迁移命令
python manage.py makemigrations
python manage.py check	# 检查是否错误
python manage.py migrate
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值