【问题标题】:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 107654: invalid start byte Django database change to MySQLUnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 107654: invalid start byte Django 数据库更改为 MySQL
【发布时间】:2021-07-21 03:15:29
【问题描述】:

我最近尝试将我的 Django 项目中的数据库从默认 SQLite 切换到 MySQL。 相应地设置 MySQL 后,我使用了以下命令:

python manage.py dumpdata > datadump.json
# to export existing data into a json file

在 settings.py 中设置 MySQL 数据库并进行所有迁移后,尝试使用以下命令将 json 文件加载到数据库:

python manage.py loaddata datadump.json
# should return sth like "Installed 59 object(s) from 1 fixture(s)"

我收到以下错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 107654: invalid start byte

现在我尝试将 mysql DB 的默认字符集设置为 utf8,但什么也没发生。 当我在Pycharm中点击datadump.json文件时,我也收到如下警告,不知道是否相关:

File was loaded with the wrong encoding: UTF-8

任何帮助将不胜感激

【问题讨论】:

    标签: python mysql django database


    【解决方案1】:

    已解决: 我使用 Pycharm 的界面重新加载了带有 UTF-8 编码的 datadump.json 文件(打开文件时应该在顶部提示您更改它)。 我在文件中的某个位置也有一个未闭合的括号,并且在修复这两个问题后一切正常。

    【讨论】:

      猜你喜欢
      • 2021-01-05
      • 2020-12-26
      • 1970-01-01
      • 2018-10-15
      • 2021-11-24
      • 2022-09-26
      • 2020-03-12
      • 2020-05-08
      • 1970-01-01
      相关资源
      最近更新 更多