1

希望你能帮我!

我在sqlalchemy中有如下关系:

class Location(db.Model, DateModified, Sluggable):
    __tablename__ = 'location'
    __sluggable__ = {
        'populate_from': 'title',
        'always_update': True
    }    
    id = db.Column(db.Integer, primary_key=True)

    title = db.Column(db.String(80))

    ...

    parent_location_id = db.Column(db.Integer, db.ForeignKey('location.id'), index=True)
    parent_location = db.relationship(lambda: Location, remote_side=id, backref='child_locations')

我真的不确定如何调试在保存父位置时间歇性地烧瓶管理员或 sqlalchemy 丢失 parent_location_id 的事实。

这种消失的行为似乎是相当随机的。

任何对我如何调试它有任何线索的人都会有很大帮助!

谢谢。

4

1 回答 1

0

乔斯,谢谢你提醒我回答这个问题。

只是我的模型中有一个隐藏在表单上的 backref。因此,正在提交的数据是空的,清除了关系。

故事的寓意:不要有隐藏在管理表单中的反向引用。

于 2014-09-15T11:32:24.587 回答