在终端命令行创建迁移项 输入(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'的更多相关文章

  1. Django项目与mysql交互进行数据迁移时报错:AttributeError: 'str' object has no attribute 'decode'

    问题描述 Django项目启动,当我们执行命令 python manage.py makemigrations 出现如下错误: File , in last_executed_query query ...

  2. Django2.2报错 AttributeError: 'str' object has no attribute 'decode'

    准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...

  3. 执行: python manage.py makemigrations报AttributeError: 'str' object has no attribute 'decode'

    找到错误代码(line146):query = query.encode(errors='replace') 解决方法:把decode改为encode即可.

  4. Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'

    pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...

  5. Django 运行报异常:AttributeError: 'str' object has no attribute 'get'

    Technorati Tags: Python,Django,Web 在使用django.contrib.auth用户机制进行用户的验证.登录.注销操作时,遇到这个异常. 首先是写了一个登录的视图,要 ...

  6. pyinstaller打包报错:AttributeError: 'str' object has no attribute 'items'

    导致原因和python多数奇奇怪怪的问题一样,依赖包的版本问题. 解决办法: 对setuptools这个包进行升级,链接在这里 https://pypi.org/project/setuptools/ ...

  7. django2.0+连接mysql数据库迁移时候报错

    django2.0+连接mysql数据库迁移时候报错 情况一 错误信息 django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 ...

  8. 目标平台、活动平台 配置,出现未能加载文件或程序集“xxx”或它的某一个依赖项报错

    今天在做动态加载程序集的时候,发现明明程序集存在的情况下,还是依然报“未能加载文件或程序集“xxx”或它的某一个依赖项报错”的错误,排除了程序和配置的错误后,怀疑是否是环境的问题,于是百度加msdn后 ...

  9. eclipse 向HDFS中创建文件夹报错 permission denied

    环境:win7  eclipse    hadoop 1.1.2 当执行创建文件的的时候, 即: String Path = "hdfs://host2:9000"; FileSy ...

  10. Redis创建集群报错

    Redis创建集群报错: 1:任何一个集群节点中都不能存在数据,如果有备份一下删除掉aof文件或rdb文件 2: nodes-集群端口.conf 文件存的会有报错记录,所以该文件也要删除

随机推荐

  1. .NET周报 【4月第2期 2023-04-08】

    国内文章 LRU缓存替换策略及C#实现 https://www.cnblogs.com/eventhorizon/p/17290125.html 这篇文章讲述了缓存替换策略,特别是LRU算法.LRU算 ...

  2. XmlSerializer 反射类型xxx时出错,反射属性xxx时出错。

    在使用XmlSerializer将类序列化成XML时出错,看到InnerException的message可以知道是这个receiver里有错误,进入这个类查看一下代码发现有重名的类 NodeId类修 ...

  3. 深度学习-06(PaddlePaddle体系结构与基本概念[Tensor、Layer、Program、Variable、Executor、Place]线性回归、波士顿房价预测)

    文章目录 深度学习-06(PaddlePaddle基础) paddlePaddle概述 PaddlePaddle简介 什么是PaddlePaddle 为什么学习PaddlePaddle PaddleP ...

  4. 玩一玩 Ubuntu 下的 VSCode 编程

    一:背景 1. 讲故事 今天是五一的最后一天,想着长期都在 Windows 平台上做开发,准备今天换到 Ubuntu 系统上体验下,主要是想学习下 AT&T 风格的汇编,这里 Visual S ...

  5. Pwn系列之Protostar靶场 Stack3题解

    (gdb) disass main Dump of assembler code for function main: 0x08048438 <main+0>: push ebp 0x08 ...

  6. JavaWeb 中 Filter过滤器

    Filter过滤器 每博一文案 师傅说:人生无坦途,累是必须的背负,看多了,人情人暖,走遍了离合聚散,有时会 在心里对自己说,我想,我是真的累了,小时候有读不完的书,长大后有赚不尽的力. 白天在外要奋 ...

  7. 2022-06-13:golang中,[]byte和结构体如何相互转换?

    2022-06-13:golang中,[]byte和结构体如何相互转换? 答案2022-06-13: []byte和结构体的转换的应用场景是数据解析. 代码里有两种方法,一种是内存不共用,另一种是内存 ...

  8. 2022-02-28:k8s安装adminer,yaml如何写?

    2022-02-28:k8s安装adminer,yaml如何写? 答案2022-02-28: yaml如下: apiVersion: apps/v1 kind: Deployment metadata ...

  9. CST为什么要关闭 GPU 卡的 ECC 模式而开启 TCC 模式?操作使用【详解】

    在使用CST软件之前,我们一般建议大家关闭 GPU 卡的 ECC 模式而开启 TCC 模式.那么,为什么要进行这样一个操作呢?在此之前,给大家科普一下什么是"ECC"和" ...

  10. C语言访问数据对象在内存中真实位模式的一个方法

    在判定机器采用大端还是小端存储时,可以按字节输出某数据对象的机器表示的位模式.机器表示的位模式即某数据对象在内存中的二进制串.下面是一个访问数据对象位模式的方法: //传入一个数据对象,从低地址到高地 ...