1.输入:
python3 manage.py makemigrations
出现的错误:
ModuleNotFoundError: No module named 'MySQLdb'
解决方案:要导入pymysql模块
那么具体在哪里导入呢?如下图:
在Diango_ORM_Muti文件下的 __init__.py文件里
写下面代码:
import pymysql
pymysql.install_as_MySQLdb()
导入pymysql模块的位置.png
2.重现输入:python3 manage.py makemigrations
出现错误:
File "~/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文件中,注释点下面的代码
# if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
3.重现输入:python3 manage.py makemigrations
出现错误:
File ".../mysql/operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
解决方案
def last_executed_query(self, cursor, sql, params):
query = getattr(cursor, '_executed', None)
if query is not None:
query = query.decode(errors='replace') 修改代码:decode修改成encode
return query
4.重现输入 :python3 manage.py makemigrations
Migrations for 'app01':
app01/migrations/0001_initial.py
- Create model Author
- Create model Publish
- Create model Book
5.输入 :python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, app01, auth, contenttypes, sessions
Running migrations:
.......
网友评论