我有两个表,News
和Files
:
# unrelated columns removed
class News(db.Model):
id = db.Column(db.Integer, primary_key=True)
file_id_logo = db.Column(db.Integer, db.ForeignKey('files.id'))
logo = db.relationship('File', lazy=False)
class File(db.Model):
id = db.Column(db.Integer, primary_key=True)
news_id = db.Column(db.Integer, db.ForeignKey('news.id'))
news = db.relationship('News', lazy=False, backref=db.backref('files'))
[添加file_id_logo
fkey之后,SQLalchemy引发了CircularDependencyError。我已经在post_update=True
关系中尝试过logo
,但它没有任何改变。
解决此问题的正确方法是什么?
以下情况是可能的(如果有关系):
logo
。logo
,则引用的文件也将此新闻作为其news
。use_alter –传递给基础的ForeignKeyConstraint,以指示应从CREATE TABLE / DROP TABLE语句在外部生成/删除约束。有关详情,请参见该类的构造函数。