Djiango 创建迁移项报错query = query.decode(errors='replace') AttributeError: 'str' object has no attribute 'decode'
在终端命令行创建迁移项 输入(python manage.py makemigrations) 或(python manage.py migrate)时出现报错信息:
Traceback (most recent call last):
File “manage.py”, line 21, in
main()
File “manage.py”, line 17, in main
execute_from_command_line(sys.argv)
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management_init_.py”, line 381, in execute_from_command_line
utility.execute()
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management_init_.py”, line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\base.py”, line 323, in run_from_argv
self.execute(*args, **cmd_options)
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\base.py”, line 364, in execute
output = self.handle(*args, **options)
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\base.py”, line 83, in wrapped
res = handle_func(*args, **kwargs)
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\core\management\commands\makemigrations.py”, line 101, in handle
loader.check_consistent_history(connection)
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\migrations\loader.py”, line 283, in check_consistent_history
applied = recorder.applied_migrations()
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\migrations\recorder.py”, line 73, in applied_migrations
if self.has_table():
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\migrations\recorder.py”, line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\base\base.py”, line 256, in cursor
return self._cursor()
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\base\base.py”, line 233, in _cursor
self.ensure_connection()
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\base\base.py”, line 217, in ensure_connection
self.connect()
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\base\base.py”, line 197, in connect
self.init_connection_state()
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\mysql\base.py”, line 232, in init_connection_state
if self.features.is_sql_auto_is_null_enabled:
File “C:\Program Files (x86)\Python37-32\lib\site-packages\django\utils\functional.py”, line 80, in get
res = instance.dict[self.name] = self.func(instance)
File “C:\Program Files (x86)\Python37-32\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 “C:\Program Files (x86)\Python37-32\lib\site-packages\django\db\backends\utils.py”, line 103, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File “C:\Program Files (x86)\Python37-32\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’
**解决方法:**C:\Program Files (x86)\Python37-32\Lib\site-packages\django\db\backends\mysql\operations.py
将decode改为encode即可解决
找到对应文件并打开,修改内容:

然后回到cmd重新输入命令后

Djiango 创建迁移项报错query = query.decode(errors='replace') AttributeError: 'str' object has no attribute 'decode'的更多相关文章
- Django项目与mysql交互进行数据迁移时报错:AttributeError: 'str' object has no attribute 'decode'
问题描述 Django项目启动,当我们执行命令 python manage.py makemigrations 出现如下错误: File , in last_executed_query query ...
- Django2.2报错 AttributeError: 'str' object has no attribute 'decode'
准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...
- 执行: python manage.py makemigrations报AttributeError: 'str' object has no attribute 'decode'
找到错误代码(line146):query = query.encode(errors='replace') 解决方法:把decode改为encode即可.
- Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'
pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...
- Django 运行报异常:AttributeError: 'str' object has no attribute 'get'
Technorati Tags: Python,Django,Web 在使用django.contrib.auth用户机制进行用户的验证.登录.注销操作时,遇到这个异常. 首先是写了一个登录的视图,要 ...
- pyinstaller打包报错:AttributeError: 'str' object has no attribute 'items'
导致原因和python多数奇奇怪怪的问题一样,依赖包的版本问题. 解决办法: 对setuptools这个包进行升级,链接在这里 https://pypi.org/project/setuptools/ ...
- django2.0+连接mysql数据库迁移时候报错
django2.0+连接mysql数据库迁移时候报错 情况一 错误信息 django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 ...
- 目标平台、活动平台 配置,出现未能加载文件或程序集“xxx”或它的某一个依赖项报错
今天在做动态加载程序集的时候,发现明明程序集存在的情况下,还是依然报“未能加载文件或程序集“xxx”或它的某一个依赖项报错”的错误,排除了程序和配置的错误后,怀疑是否是环境的问题,于是百度加msdn后 ...
- eclipse 向HDFS中创建文件夹报错 permission denied
环境:win7 eclipse hadoop 1.1.2 当执行创建文件的的时候, 即: String Path = "hdfs://host2:9000"; FileSy ...
- Redis创建集群报错
Redis创建集群报错: 1:任何一个集群节点中都不能存在数据,如果有备份一下删除掉aof文件或rdb文件 2: nodes-集群端口.conf 文件存的会有报错记录,所以该文件也要删除
随机推荐
- Semantic Kernel 入门系列:💬Semantic Function
如果把提示词也算作一种代码的话,那么语义技能所带来的将会是全新编程方式,自然语言编程. 通常情况下一段prompt就可以构成一个Semantic Function,如此这般简单,如果我们提前可以组织好 ...
- day134:2RenMJ:TypeScript的抽象类&装饰器&命名空间&模块&编译配置文件&python中的类型注解
目录 1.抽象类 2.装饰器 3.命名空间 4.模块 5.编译配置文件 6.python的类型注解 1.抽象类 抽象类(abstract class)做为其它派生类的基类使用. 它们一般不会直接被实例 ...
- Linux普通用户使用docker以及docker-compose
# 添加limstorm普通用户到docker用户组 sudo gpasswd -a limstorm docker # 切换docker用户组,该命令类似login指令,当它是以相同的帐号,另一个群 ...
- CommunityToolkit.Mvvm系列文章导航
包 CommunityToolkit.Mvvm (又名 MVVM 工具包,以前名为 Microsoft.Toolkit.Mvvm) 是一个现代.快速且模块化的 MVVM 库. 它是 .NET 社区工具 ...
- Java学习笔记03
1. 流程控制语句 在一个程序执行的过程中,各条语句的执行顺序对程序的结果是有直接影响的.所以,我们必须清楚每条语句的执行流程.而且,很多时候要通过控制语句的执行顺序来实现我们想要的功能. 1.1 分 ...
- Go/Python RPC使用
Remote Procedure Call 简单RPC调用 server实现 // 注册接口 type HelloService struct{} func (s *HelloService) Hel ...
- Golang爬虫:使用正则表达式解析HTML
之前所写的爬虫都是基于Python,而用Go语言实现的爬虫具有更高的性能. 第一个爬虫 使用http库,发起http请求 package main import ( "fmt" & ...
- node使用react项目启动错误TSError: ⨯ Unable to compile TypeScript:
1.错误内容 return new TSError(diagnosticText, diagnosticCodes) ^ TSError: ⨯ Unable to compile TypeScript ...
- Kubernetes(K8S) kubesphere 介绍
使用 Kubeadm 部署 Kubernetes(K8S) 安装--附K8S架构图 官网地址:https://kubesphere.com.cn/ KubeSphere 是个全栈的Kubernetes ...
- 从 API 网关聊到 API 管理
在 API 管理中,通常会有这些痛点: 1.企业不清楚到底有多少个API,无法形成API资产管理等问题. 2.API在不同集群的生命周期问题. 3.API运行状态监控和告警问题. 4.API请求限流. ...