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 文件存的会有报错记录,所以该文件也要删除
随机推荐
- 点亮LED灯_STM32第一课
基本原理 初始化Hal库 HAL_Init(); 系统时钟 SystemClock_Config(); GPIOB初始化:GPIOB模式为推挽输出,GPIO引脚为Pin_5.0.1代表红绿蓝LED ...
- 【Ubuntu】 Perf工具的使用
一.perf工具的安装 sudo apt-get install linux-tools-common sudo apt-get install linux-tools-"$(uname - ...
- Java学习笔记03
1. 流程控制语句 在一个程序执行的过程中,各条语句的执行顺序对程序的结果是有直接影响的.所以,我们必须清楚每条语句的执行流程.而且,很多时候要通过控制语句的执行顺序来实现我们想要的功能. 1.1 分 ...
- 一文理解TS泛型
当我们在编写 TypeScript 代码时,经常会遇到需要通用(Generic)的情况,这时候,泛型就是我们的好帮手了.在本篇文章中,我们将深入介绍 TypeScript 泛型的概念以及如何使用. 什 ...
- Docker快速部署Hadoop环境
文章目录 安装环境 安装过程 拉取镜像 在Docker中创建网络,方便通信 创建Master节点 创建slave1和slave2节点 分别进入三个容器修改hosts文件 在Master执行集群初始化 ...
- 爆肝一周,我开源了ChatGPT 中文版接口,官方1:1镜像支持全部 官方接口
这里实现我之前文章承诺承接上文 人人实现ChatGPT自由,手把手教你零撸部署自己聊天私服 现在ChatGPT 提供了api接口 可以让我自己对接去实现我们自己想要gpt应用,但是由于一些原因,国内也 ...
- 配置pip源
1.使用配置文件配置文件[global]trusted-host=pypi.doubanio.comindex-url=https://pypi.doubanio.com/simple配置文件放置位置 ...
- 记录-开发WPF项目中的一个疑惑
背景 项目技术栈:C#,WPF当前我想要实现点击某个按钮就可以跳转到某个界面,翻阅了项目中的代码,看到了 // 按钮事件 private void Btn_Click(object sender, R ...
- phpstudy-pikachu-数字型注入(post)
抓包搞到格式 id=1&submit=%E6%9F%A5%E8%AF%A2 查字符段 id=1 order by 2&submit=%E6%9F%A5%E8%AF%A2 id=1 un ...
- Jenkins(1)-安装教程
我用的服务器是阿里云服务器, 服务器系统: CentOS7.9, 不同的操作系统需要下载不同的软件包, 对应的链接如下https://www.jenkins.io/zh/download/ 1) 软件 ...