我有桌子模型:
class Example(Base):
__tablename__ = 'example'
id = Column(ForeignKey(u'visit.id', ondelete=u'CASCADE', onupdate=u'CASCADE'), primary_key=True, unique=True)
startdate = Column(Date, nullable=False)
enddate = Column(Date)
然后我尝试插入新行:
session.begin()
i = sqlalchemy.insert(Example)
i = i.values({'id': 1, 'startdate': 1570798620, 'enddate': 1572526620})
session.execute(i)
session.commit()
但是我收到下一个错误:'Join' object has no attribute 'implicit_returning'
这是什么问题?
答案 0 :(得分:0)
插入SQLAlchemy ORM模型实例的正确方法是创建您的类的实例,然后将其.add()
插入会话(ORM Tutorial reference):
session.begin()
ex = Example(id=1, startdate=1570798620, enddate=1572526620)
session.add(ex)
session.commit()