gpt4 book ai didi

Python cdecimal.Decimal 和 SQLAlchemy _mysql_exceptions.Warning

转载 作者:行者123 更新时间:2023-11-29 00:48:08 25 4
gpt4 key购买 nike

我正在构建一个使用 SQLAlchemy 而不是 MySQL 的 Django 应用程序。我使用的是 cdecimal 而不是内置的 Decimal。在我的一个表中,我有一个数值列 (value = Column(Numeric(10, 5))。当我在我的 Django 应用程序中为此表创建一个新条目时,使用以下 SQL 回显:

INSERT INTO my_table (date, value) VALUES (2012-03-11, 875334.670)

这会导致在提交时抛出以下异常:

_mysql_exceptions.Warning: Out of range value for column 'value' at row 1  

当我在 mysql 客户端中运行相同的查询时,完全没有问题。我什至尝试包装添加条目的代码:

import warnings
from sqlalchemy import exc as sa_exc
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=sa_exc.SAWarning)

这是怎么回事?

谢谢!

最佳答案

试试这个:

INSERT INTO my_table (date, value) VALUES ('2012-03-11', 875334.670)

关于Python cdecimal.Decimal 和 SQLAlchemy _mysql_exceptions.Warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9657913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com