0

我正在使用 django 1.8.9 和 MySQL 5.7.17。我有一个下表:

+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| brand    | varchar(255) | YES  | MUL | NULL    |                |
| new_info | json         | YES  |     | NULL    |                |
| keywords | json         | YES  |     | NULL    |                |
| notes    | varchar(255) | YES  |     | NULL    |                |
| id       | mediumint(9) | NO   | MUL | NULL    | auto_increment |
+----------+--------------+------+-----+---------+----------------+

在 django 我有这个模型(JSONField来自 django_mysql):

class info_by_kw(Model):
    brand = ForeignKey(Brand, on_delete=CASCADE, db_column='brand')
    # new_info = JSONField(blank=True, null=True)
    keywords = JSONField(blank=True, null=True)
    notes = CharField(max_length=255, blank=True, null=True)

保存数据后,我得到一个非常有意义的错误:(-1,“错误完全重击”)。无论如何,它最终会出现在以下 SQL 语句中:

UPDATE `products_info_by_kw` SET `brand` = _binary'BINGO!', `keywords` = _binary'[[\\"Tomato\\", \\"Madness\\"]]', `notes` = _binary'' WHERE `products_info_by_kw`.`id` = 48;

或多或少的预期结果:

ERROR 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.

简短的搜索给出了这个结果:https ://code.djangoproject.com/ticket/26140 ,所以也许这是正确的做法,我的 mysql(或 django)配置错误。有谁知道如何解决它?

4

1 回答 1

0

事实证明,最近在https://github.com/PyMySQL/mysqlclient-python中的 _binary 前缀周围有些激动(如果不是大惊小怪的话)。所以我使用的版本 1.3.8 受到了它的影响,而在 1.3.9 中,更改已被恢复。我的代码现在按预期工作。

于 2017-01-26T11:36:49.153 回答