我有完全相同的错误,我尝试修改从数据库中获取的SQLAlchemy对象。当我打印它时,我看到一个元组,请检查它不是。我通过重构我的模型来解决问题,我想在我的关系中添加一些字段。首先我有:
assoc_host_software = Table("host_software", Base.metadata,
Column("host_id", Integer, ForeignKey("host.id")),
Column("software_id", Integer, ForeignKey("software.id")),
)
然后我尝试。
assoc_host_software = Table("host_software", Base.metadata,
Column("host_id", Integer, ForeignKey("host.id")),
Column("software_id", Integer, ForeignKey("software.id")),
Column("in_date",DateTime, unique=False, nullable=True),
Column("out_date",DateTime, unique=False, nullable=True)
)
当我从assoc_host_software获取对象并尝试更新它时,我得到了与你相同的错误。
我明白(并记得)这不是修改多对多关系对象的正确方式,
所以
我将我的模型转换为
class Host_Software(Base):
"""Model for relation host software."""
__tablename__ = 'host_software'
host_id = Column(Integer, ForeignKey("host.id"), primary_key=True)
software_id = Column(Integer, ForeignKey("software.id"), primary_key=True)
in_date = Column(DateTime, unique=False, nullable=True)
out_date = Column(DateTime, unique=False, nullable=False)
software = relationship("Software", backref="software_associations")
host = relationship("Host", backref="host_associations")
我希望那能帮到你
Topic
的连接。 - dirn