遇到的问题:
1.python3 manage.py makemigrations时显示:你的版本可能需要升级(版本不兼容,提示mysqlclient不兼容)
解决方法:1.升级版本 2.找到lib/pythonxx/site-packages/django/db/backends/mysql/base 将base文件夹里面的关于检查版本的代码注释
# 找到base.py文件,注释掉 base.py 中如下部分(35/36行) if version < (1, 3, 3): raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
2.报错:AttributeError: ‘str‘ object has no attribute ‘decode‘
解决方法:找到lib/pythonxx/site-packages/django/db/backends/mysql/operations文件,将第146行的decode改为encode
if query is not None: query = query.encode(errors=‘replace‘) return query
3.创建数据库的时候将编码问题,一般utf-8,不然在pycharm里面导入数据不能输入中文
4.页面的操作的时候:html里面的路径用//扩起来
5.在Django里面进行数据库外键的连接:
publisher = models.ForeignKey(to="Publisher",on_delete=models.CASCADE)
我自己的版本需要加上
on_delete=models.CASCADE
原文:https://www.cnblogs.com/FlowerNotGiveYou/p/12668859.html