【发布时间】:2017-01-20 17:47:23
【问题描述】:
我正在尝试使用以下代码创建一个表的实例:
c = 'dcoh92j'
new_comment = Comment(rcomment = c, rtime = datetime.datetime.now())
但我收到此错误:
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 0 - probably unsupported type. [SQL: 'INSERT INTO comments (rcomment, rtime) VALUES (?, ?)'] [parameters: (Comment(id='dcoh92j'), datetime.datetime(2017, 1, 20, 12, 38, 38, 836433))
这是我的表架构:
class Comment(Base):
__tablename__ = 'comments'
id = Column(Integer, Sequence('comment_id_seq'), primary_key=True)
rcomment = Column(String)
rtime = Column(String)
def __repr__(self):
return "<Comment(rcomment='{0}', rtime='(1)')>".format(self.rcomment, self.rtime)
- 为什么 SQLAlchemy 认为我试图插入数据库的参数是
(Comment(id='dcoh92j'), datetime.datetime(2017, 1, 20, 12, 38, 38, 836433)?而不仅仅是'dcoh92j'和2017, 1, 20, 12, 38, 38, 836433 -
Comment(id='dcoh92j')来自哪里?
完整代码here.
【问题讨论】:
标签: python sqlite sqlalchemy