我正在尝试使用cdecimal来存储数据库中的货币值。 SQLAlchemy文档
import sys
import cdecimal
sys.modules["decimal"] = cdecimal
我已经连接了我的PostgreSQL数据库,如下所示:
:
sqlalchemy.url = postgresql+psycopg2://user:password@host:port/dbname
我已经设置了模型,就像这样:
class Exchange(Base):
amount = Column(Numeric)
...
def __init__(self, amount):
self.amount = cdecimal.Decimal(amount)
然而,每当我这样做时,都会出现以下错误:
ProgrammingError: (ProgrammingError) can't adapt type 'cdecimal.Decimal' 'INSERT INTO...
我做错了什么?