在安装 conda 后,pip3 报不是内部命令等错误的解决方式
执行 :
python -m ensurepip
init.py 添加
import pymysql
pymysql.install_as_MySQLdb()
执行 python manage.py makemigrations 报错如下:
...
return _bootstrap._gcd_import(name[level:], package, level)
File "G:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", l
ine 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; y
ou have 0.9.3.
mysqlclient 版本不适合,可以更新版本或者如下操作,G:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py文件注释以下内容
#if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
注释后,接着又报如下错误
...
File "G:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 231, in init_connection_state
if self.features.is_sql_auto_is_null_enabled:
File "G:\ProgramData\Anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "G:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\mysql\features.py", line 82, in is_sql_auto_is_null_enabled
cursor.execute('SELECT @@SQL_AUTO_IS_NULL')
File "G:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 103, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "G:\ProgramData\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'
将报错文件 G:\ProgramData\Anaconda3\lib\site-packages\django\db\backends\mysql\operations.py中的
query = query.decode(errors='replace')改为
query = query.encode(errors='replace')
最后再执行
python manage.py makemigrations
python manage.py sqlmigrate