我有以下使用 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/