今天执行drf实验的时候,碰到一下错误,记录一下
系统环境:Windows 10 (64)
话不多说,上图
执行数据库迁移的时候,如下报错~~~
![image.png](https://img-blog.csdnimg.cn/img_convert/a3999163d30eae1ee8f9123a10238af4.png)
解决办法是找到下面文件
![image.png](https://img-blog.csdnimg.cn/img_convert/4c83894ce28854f4cb29da996a6c2373.png)
将decode改为encode就可以了
![image.png](https://img-blog.csdnimg.cn/img_convert/26661c59afa6c8236565079f5346cb09.png)
执行数据库迁移碰到下面错误
python manage.py makemigrations
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-U3HmcIv6-1632465883996)(https://upload-images.jianshu.io/upload_images/19833353-af90f6d9c31ba174.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]
python manage.py migrate
![image.png](https://img-blog.csdnimg.cn/img_convert/2c6be09780b92da01f9d6707bb737807.png)
Django2.1不再支持MySQL5.5,必须5.6版本以上
django降级
pip install Django==2.0.0 -i https://pypi.douban.com/simple
或者 mysql升级
然后又出现了下面的错误
![image.png](https://img-blog.csdnimg.cn/img_convert/7fe564ce1015f4d888edcb215bad2839.png)
发现还是版本不兼容,是djangorestframework需要2.2.0以上才可以,没办法只能把数据库卸载了重装,装上5.7.0的试一下吧
![image.png](https://img-blog.csdnimg.cn/img_convert/200b38125ea1fd672cd9b60f811209a4.png)
先提前建立好数据库students
![image.png](https://img-blog.csdnimg.cn/img_convert/702cb8eda354a33c27770dc233b5a91f.png)
执行数据库迁移
![image.png](https://img-blog.csdnimg.cn/img_convert/896b28aaa23f403aa19ca41dec85f43f.png)
但是没有生成students表
![image.png](https://img-blog.csdnimg.cn/img_convert/8e0dad9069583668a230ae48289142c3.png)
怎么办了?快崩溃了~~~
没事,别慌,慢慢来
1:先删除整个数据库,重新建立一个数据库 students
2:执行这个命令,强制生成 python manage.py makemigrations --empty students
3:执行迁移 python manage.py migrate
发现只有迁移记录,和默认的表,就是没有我们刚刚建立的表
再次确认检测代码model模型,发现没有问题
![image.png](https://img-blog.csdnimg.cn/img_convert/ecd0818dde1422ed353c8fbc48e4e0aa.png)
4:然后我们再次正常执行
![image.png](https://img-blog.csdnimg.cn/img_convert/54f9bae6ba17a6e19af08ff2decbd994.png)
5:发现这次可以了,student表又回来了~~~~
![image.png](https://img-blog.csdnimg.cn/img_convert/77d5acf707e0fa08cc6d3439fbf2de9b.png)
6:所以遇到事情别慌,多多试试总会成功的~~~