mysql - Peewee 选择十进制字段?

标签 mysql python-3.x peewee

我有以下使用 Peewee 库的请求:

return Products.select(Products.price, Products.sku, Products.manufacturer_id).where(Products.sku == article).get()

其中 Products.price 是 MySQL 中 decimal(15,4) 类型的字段

这是模型:

class Products(peewee.Model):
    product_id = IntegerField(primary_key=True)
    sku = peewee.CharField()
    model = peewee.CharField()
    price = peewee.DecimalField(max_digits=15, decimal_places=4)
    manufacturer_id = peewee.IntegerField()

    class Meta:
        database = get_db_connection()
        table_name = 'oc_product'

当我运行上述查询时,出现错误:

Error has occurred: Cannot convert b'6403.0000' to Decimal

怎么了?

最佳答案

我认为 Peewee 中存在 Python 3 错误。如果此补丁解决了您的问题,请告诉我:

https://github.com/coleifer/peewee/commit/cd07f4e01a1262166d8944736e11d0681fb76214

关于mysql - Peewee 选择十进制字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48593080/

相关文章:

python - 如何在 Python 中使用保留字的变量名

python - python 的 ORM 库 peewee 中与foreignkeyfield对象一起使用的 "related_name"属性是什么?

php - 是我做错了什么还是 php 不支持这个?

MySQL "cant create test file", "Failed to set datadir or directory",无法使用初始密码连接

mysql - mysql 上的触发更新第二次运行

python - 在Python中使用多进程构建Gurobi表达式

php - Zend Model Mapper fetchAll() 忽略我的 WHERE 子句

python - 在 Python 3.6+ 中按位置高效访问字典项目

python - 如何删除 XML 中仅包含空格的空 XML 标记?

python - 在 python 中插入或更新一条 peewee 记录